Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
import fal_client
|
4 |
import time
|
@@ -6,18 +5,17 @@ import requests
|
|
6 |
from io import BytesIO
|
7 |
from PIL import Image
|
8 |
|
9 |
-
|
10 |
-
if "FAL_KEY" not in os.environ:
|
11 |
-
os.environ["FAL_KEY"] = "YOUR_API_KEY" # Replace with your actual API key
|
12 |
-
|
13 |
-
def generate_image(prompt):
|
14 |
try:
|
15 |
-
#
|
|
|
|
|
|
|
16 |
image_size = "landscape_4_3"
|
17 |
num_images = 1
|
18 |
enable_safety_checker = True
|
19 |
safety_tolerance = "2"
|
20 |
-
|
21 |
handler = fal_client.submit(
|
22 |
"fal-ai/flux-pro/v1.1",
|
23 |
arguments={
|
@@ -25,10 +23,10 @@ def generate_image(prompt):
|
|
25 |
"image_size": image_size,
|
26 |
"num_images": num_images,
|
27 |
"enable_safety_checker": enable_safety_checker,
|
28 |
-
"safety_tolerance": safety_tolerance
|
29 |
},
|
30 |
)
|
31 |
-
|
32 |
# Wait for the result
|
33 |
while True:
|
34 |
status = handler.status()
|
@@ -37,14 +35,14 @@ def generate_image(prompt):
|
|
37 |
elif status["status"] == "failed":
|
38 |
return "The image generation failed."
|
39 |
time.sleep(1) # Wait for 1 second before checking again
|
40 |
-
|
41 |
result = handler.get()
|
42 |
if not result["images"]:
|
43 |
return "No images were generated."
|
44 |
-
|
45 |
image_info = result["images"][0]
|
46 |
image_url = image_info["url"]
|
47 |
-
|
48 |
# Download the image
|
49 |
response = requests.get(image_url)
|
50 |
if response.status_code == 200:
|
@@ -58,10 +56,13 @@ def generate_image(prompt):
|
|
58 |
# Set up the Gradio interface
|
59 |
iface = gr.Interface(
|
60 |
fn=generate_image,
|
61 |
-
inputs=
|
|
|
|
|
|
|
62 |
outputs=gr.Image(label="Generated Image"),
|
63 |
title="FLUX1.1 [pro] Image Generation",
|
64 |
-
description="Generate an image using the FLUX1.1 [pro] model by providing a text prompt."
|
65 |
)
|
66 |
|
67 |
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import fal_client
|
3 |
import time
|
|
|
5 |
from io import BytesIO
|
6 |
from PIL import Image
|
7 |
|
8 |
+
def generate_image(api_key, prompt):
|
|
|
|
|
|
|
|
|
9 |
try:
|
10 |
+
# Set the API key provided by the user
|
11 |
+
fal_client.api_key = api_key
|
12 |
+
|
13 |
+
# Default parameters
|
14 |
image_size = "landscape_4_3"
|
15 |
num_images = 1
|
16 |
enable_safety_checker = True
|
17 |
safety_tolerance = "2"
|
18 |
+
|
19 |
handler = fal_client.submit(
|
20 |
"fal-ai/flux-pro/v1.1",
|
21 |
arguments={
|
|
|
23 |
"image_size": image_size,
|
24 |
"num_images": num_images,
|
25 |
"enable_safety_checker": enable_safety_checker,
|
26 |
+
"safety_tolerance": safety_tolerance,
|
27 |
},
|
28 |
)
|
29 |
+
|
30 |
# Wait for the result
|
31 |
while True:
|
32 |
status = handler.status()
|
|
|
35 |
elif status["status"] == "failed":
|
36 |
return "The image generation failed."
|
37 |
time.sleep(1) # Wait for 1 second before checking again
|
38 |
+
|
39 |
result = handler.get()
|
40 |
if not result["images"]:
|
41 |
return "No images were generated."
|
42 |
+
|
43 |
image_info = result["images"][0]
|
44 |
image_url = image_info["url"]
|
45 |
+
|
46 |
# Download the image
|
47 |
response = requests.get(image_url)
|
48 |
if response.status_code == 200:
|
|
|
56 |
# Set up the Gradio interface
|
57 |
iface = gr.Interface(
|
58 |
fn=generate_image,
|
59 |
+
inputs=[
|
60 |
+
gr.Textbox(label="API Key", placeholder="Enter your API key here...", type="password"),
|
61 |
+
gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
62 |
+
],
|
63 |
outputs=gr.Image(label="Generated Image"),
|
64 |
title="FLUX1.1 [pro] Image Generation",
|
65 |
+
description="Generate an image using the FLUX1.1 [pro] model by providing your API key and a text prompt."
|
66 |
)
|
67 |
|
68 |
iface.launch()
|