DonImages commited on
Commit
b9c75da
·
verified ·
1 Parent(s): 02a3a52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -46,17 +46,20 @@ except Exception as e:
46
  exit() # Stop if model loading fails
47
 
48
  # 4. Image generation function (now decorated)
49
- @GPU(duration=65) # ONLY if in a HF Space, remove if not
50
  def generate_image(prompt):
51
  global pipeline
52
- if pipeline is None: # Should not happen, but good to check
53
  return "Error: Model not loaded!"
54
 
55
  try:
56
- image = pipeline(prompt).images[0] # Access the first image from the list
57
- return image
 
58
  except Exception as e:
59
- return f"Error generating image: {e}"
 
 
60
 
61
  # 5. Gradio interface
62
  with gr.Blocks() as demo:
 
46
  exit() # Stop if model loading fails
47
 
48
  # 4. Image generation function (now decorated)
49
+ @GPU(duration=65) # Only if in HF Space
50
  def generate_image(prompt):
51
  global pipeline
52
+ if pipeline is None:
53
  return "Error: Model not loaded!"
54
 
55
  try:
56
+ image = pipeline(prompt).images[0] # Try to generate the image
57
+ print("Image generated successfully!") # Print success message (for debugging)
58
+ return image # Return the image if successful
59
  except Exception as e:
60
+ error_message = f"Error during image generation: {e}" # Capture error
61
+ print(error_message) # Print error message to console
62
+ return error_message # Return the error message to Gradio (so it shows up)
63
 
64
  # 5. Gradio interface
65
  with gr.Blocks() as demo: