Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
3 |
|
4 |
def generate_image(prompt):
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Create Gradio interface
|
12 |
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image")
|
|
|
1 |
import gradio as gr
|
2 |
+
import random
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
|
6 |
def generate_image(prompt):
|
7 |
+
try:
|
8 |
+
# Generate a random seed for each request
|
9 |
+
random_seed = random.randint(0, 10000)
|
10 |
+
|
11 |
+
# Generate image with the model
|
12 |
+
image = model.generate(prompt, seed=random_seed)
|
13 |
+
|
14 |
+
# Check if the image is a PIL Image, if not try to convert
|
15 |
+
if isinstance(image, bytes):
|
16 |
+
image = Image.open(io.BytesIO(image))
|
17 |
+
elif not isinstance(image, Image.Image):
|
18 |
+
# If image is not in PIL format, convert or handle it
|
19 |
+
return "Error: Image not in expected format"
|
20 |
+
|
21 |
+
return image
|
22 |
+
except Exception as e:
|
23 |
+
return f"Error: {e}"
|
24 |
+
|
25 |
+
# Load the model
|
26 |
+
model = gr.load("models/black-forest-labs/FLUX.1-schnell")
|
27 |
|
28 |
# Create Gradio interface
|
29 |
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image")
|