Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,12 @@ import requests
|
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
import traceback
|
|
|
7 |
|
8 |
def generate_image(api_key, prompt, image_size='landscape_4_3', num_images=1):
|
9 |
try:
|
10 |
-
# Set the API key
|
11 |
-
|
12 |
|
13 |
handler = fal_client.submit(
|
14 |
"fal-ai/flux-pro/v1.1",
|
@@ -26,13 +27,12 @@ def generate_image(api_key, prompt, image_size='landscape_4_3', num_images=1):
|
|
26 |
response = requests.get(img_url)
|
27 |
img = Image.open(BytesIO(response.content))
|
28 |
images.append(img)
|
29 |
-
return images
|
30 |
except Exception as e:
|
31 |
error_msg = f"Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
32 |
print(error_msg)
|
33 |
-
return [gr.update(visible=
|
34 |
|
35 |
-
# Update the Gradio interface
|
36 |
with gr.Blocks() as demo:
|
37 |
gr.Markdown("# FLUX1.1 [pro] Text-to-Image Generator")
|
38 |
with gr.Row():
|
|
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
import traceback
|
7 |
+
import os
|
8 |
|
9 |
def generate_image(api_key, prompt, image_size='landscape_4_3', num_images=1):
|
10 |
try:
|
11 |
+
# Set the API key as an environment variable
|
12 |
+
os.environ['FAL_KEY'] = api_key
|
13 |
|
14 |
handler = fal_client.submit(
|
15 |
"fal-ai/flux-pro/v1.1",
|
|
|
27 |
response = requests.get(img_url)
|
28 |
img = Image.open(BytesIO(response.content))
|
29 |
images.append(img)
|
30 |
+
return [gr.update(value=images, visible=True), gr.update(visible=False)]
|
31 |
except Exception as e:
|
32 |
error_msg = f"Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
33 |
print(error_msg)
|
34 |
+
return [gr.update(visible=False), gr.update(value=error_msg, visible=True)]
|
35 |
|
|
|
36 |
with gr.Blocks() as demo:
|
37 |
gr.Markdown("# FLUX1.1 [pro] Text-to-Image Generator")
|
38 |
with gr.Row():
|