Update app.py
Browse files
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) #
|
| 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] #
|
| 57 |
-
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
-
|
|
|
|
|
|
|
| 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:
|