Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,43 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
gr.load("models/black-forest-labs/FLUX.1-schnell")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import random
|
3 |
+
import os
|
4 |
|
5 |
+
model = gr.load("models/black-forest-labs/FLUX.1-schnell")
|
6 |
+
|
7 |
+
def generate_image(text, seed, width, height, guidance_scale, num_inference_steps):
|
8 |
+
if seed is not None:
|
9 |
+
random.seed(seed)
|
10 |
+
|
11 |
+
if text in [example[0] for example in examples]:
|
12 |
+
print(f"Using example: {text}")
|
13 |
+
|
14 |
+
result_image = model(text)
|
15 |
+
|
16 |
+
print(f"Width: {width}, Height: {height}, Guidance Scale: {guidance_scale}, Inference Steps: {num_inference_steps}")
|
17 |
+
|
18 |
+
return result_image
|
19 |
+
|
20 |
+
def randomize_parameters():
|
21 |
+
seed = random.randint(0, 999999)
|
22 |
+
width = random.randint(512, 2048)
|
23 |
+
height = random.randint(512, 2048)
|
24 |
+
guidance_scale = round(random.uniform(0.1, 20.0), 1)
|
25 |
+
num_inference_steps = random.randint(1, 40)
|
26 |
+
|
27 |
+
return seed, width, height, guidance_scale, num_inference_steps
|
28 |
+
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=generate_image,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(label="Type here your imagination:", placeholder="Type or click an example..."),
|
33 |
+
gr.Slider(label="Seed", minimum=0, maximum=999999, step=1),
|
34 |
+
gr.Slider(label="Width", minimum=512, maximum=2048, step=64, value=1024),
|
35 |
+
gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024),
|
36 |
+
gr.Slider(label="Guidance Scale", minimum=0.1, maximum=20.0, step=0.1, value=3.0),
|
37 |
+
gr.Slider(label="Number of inference steps", minimum=1, maximum=40, step=1, value=28),
|
38 |
+
],
|
39 |
+
outputs=gr.Image(label="Generated Image"),
|
40 |
+
description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
|
41 |
+
)
|
42 |
+
|
43 |
+
interface.launch()
|