erwold commited on
Commit
bb47725
·
1 Parent(s): ac06db6

Initial Commit

Browse files
Files changed (1) hide show
  1. app.py +25 -30
app.py CHANGED
@@ -285,6 +285,28 @@ class FluxInterface:
285
  # Initialize the interface
286
  interface = FluxInterface()
287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  # Create Gradio interface
289
  with gr.Blocks(
290
  theme=gr.themes.Soft(),
@@ -409,32 +431,8 @@ with gr.Blocks(
409
  - 🎲 Use seeds for reproducible results
410
  """)
411
 
412
- # Set up the generation function
413
- def generate_with_error_handling(*args):
414
- try:
415
- logger.info("Starting image generation with args: %s", str(args))
416
-
417
- # 输入参数验证
418
- input_image, prompt, guidance, steps, num_images, seed, aspect_ratio = args
419
- logger.info(f"Input validation - Image: {type(input_image)}, Prompt: '{prompt}', "
420
- f"Guidance: {guidance}, Steps: {steps}, Num Images: {num_images}, "
421
- f"Seed: {seed}, Aspect Ratio: {aspect_ratio}")
422
-
423
- if input_image is None:
424
- raise ValueError("No input image provided")
425
-
426
- gr.Info("Starting image generation...")
427
- results = interface.generate(*args)
428
- logger.info("Generation completed successfully")
429
- gr.Info("Generation complete!")
430
- return [results, None]
431
- except Exception as e:
432
- error_msg = str(e)
433
- logger.error(f"Error in generate_with_error_handling: {error_msg}", exc_info=True)
434
- return [None, error_msg]
435
-
436
  submit_btn.click(
437
- fn=generate_with_error_handling,
438
  inputs=[
439
  input_image,
440
  prompt,
@@ -443,11 +441,8 @@ with gr.Blocks(
443
  num_images,
444
  seed,
445
  aspect_ratio
446
- ],
447
- outputs=[
448
- output_gallery,
449
- error_message
450
- ],
451
  show_progress=True
452
  )
453
 
 
285
  # Initialize the interface
286
  interface = FluxInterface()
287
 
288
+ # 直接将 GPU 装饰器应用在最外层的处理函数上
289
+ @spaces.GPU(duration=300)
290
+ def process_request(input_image, prompt="", guidance_scale=3.5, num_inference_steps=28, num_images=2, seed=None, aspect_ratio="1:1"):
291
+ """主处理函数,直接处理用户请求"""
292
+ try:
293
+ interface = FluxInterface()
294
+ if interface.models is None:
295
+ interface.load_models()
296
+
297
+ return interface.generate(
298
+ input_image=input_image,
299
+ prompt=prompt,
300
+ guidance_scale=guidance_scale,
301
+ num_inference_steps=num_inference_steps,
302
+ num_images=num_images,
303
+ seed=seed,
304
+ aspect_ratio=aspect_ratio
305
+ )
306
+ except Exception as e:
307
+ logger.error(f"Error during generation: {str(e)}")
308
+ raise gr.Error(f"Generation failed: {str(e)}")
309
+
310
  # Create Gradio interface
311
  with gr.Blocks(
312
  theme=gr.themes.Soft(),
 
431
  - 🎲 Use seeds for reproducible results
432
  """)
433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  submit_btn.click(
435
+ fn=process_request,
436
  inputs=[
437
  input_image,
438
  prompt,
 
441
  num_images,
442
  seed,
443
  aspect_ratio
444
+ ],
445
+ outputs=[output_gallery],
 
 
 
446
  show_progress=True
447
  )
448