Spaces:
Running
Running
add model radio
Browse files- myapp/app.py +29 -18
myapp/app.py
CHANGED
@@ -19,6 +19,11 @@ except ImportError:
|
|
19 |
|
20 |
client = InferenceClient(model="black-forest-labs/FLUX.1-schnell")
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
with gr.Blocks() as demo:
|
23 |
with gr.Row():
|
24 |
with gr.Column():
|
@@ -26,31 +31,17 @@ with gr.Blocks() as demo:
|
|
26 |
"https://wheelingvultures.bandcamp.com/album/ep", label="Text"
|
27 |
)
|
28 |
prompt = gr.TextArea("A psychedelic vulture", label="Prompt")
|
|
|
29 |
button = gr.Button("Generate")
|
30 |
with gr.Column():
|
31 |
background = gr.Image(visible=False, type="filepath")
|
32 |
scale = gr.Slider(3, 15, 9, step=1, label="Scale")
|
33 |
output = gr.Image()
|
34 |
|
35 |
-
|
36 |
-
[
|
37 |
-
partial(gr.update, interactive=False),
|
38 |
-
outputs=button,
|
39 |
-
).then(
|
40 |
-
partial(client.text_to_image, width=400, height=400),
|
41 |
-
inputs=prompt,
|
42 |
-
outputs=background,
|
43 |
-
).then(
|
44 |
-
partial(gr.update, interactive=True),
|
45 |
-
outputs=button,
|
46 |
-
)
|
47 |
|
48 |
-
|
49 |
-
triggers=[text.submit, background.change, scale.change],
|
50 |
-
inputs={text, background, scale},
|
51 |
-
outputs=output,
|
52 |
-
)
|
53 |
-
def generate_code(data: dict[Component, Any]):
|
54 |
if data.get(background) is None:
|
55 |
return None
|
56 |
|
@@ -67,6 +58,26 @@ with gr.Blocks() as demo:
|
|
67 |
|
68 |
return Image.open(temp_file.name)
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
if __name__ == "__main__":
|
72 |
demo.launch()
|
|
|
19 |
|
20 |
client = InferenceClient(model="black-forest-labs/FLUX.1-schnell")
|
21 |
|
22 |
+
MODELS = [
|
23 |
+
"stabilityai/stable-diffusion-3.5-large",
|
24 |
+
"black-forest-labs/FLUX.1-schnell",
|
25 |
+
]
|
26 |
+
|
27 |
with gr.Blocks() as demo:
|
28 |
with gr.Row():
|
29 |
with gr.Column():
|
|
|
31 |
"https://wheelingvultures.bandcamp.com/album/ep", label="Text"
|
32 |
)
|
33 |
prompt = gr.TextArea("A psychedelic vulture", label="Prompt")
|
34 |
+
model = gr.Radio(MODELS, value=MODELS[0], label="Model")
|
35 |
button = gr.Button("Generate")
|
36 |
with gr.Column():
|
37 |
background = gr.Image(visible=False, type="filepath")
|
38 |
scale = gr.Slider(3, 15, 9, step=1, label="Scale")
|
39 |
output = gr.Image()
|
40 |
|
41 |
+
def generate_background(data: dict[Component, Any]):
|
42 |
+
return client.text_to_image(data[prompt], model=data[model]), None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
def generate_output(data: dict[Component, Any]):
|
|
|
|
|
|
|
|
|
|
|
45 |
if data.get(background) is None:
|
46 |
return None
|
47 |
|
|
|
58 |
|
59 |
return Image.open(temp_file.name)
|
60 |
|
61 |
+
gr.on(
|
62 |
+
[button.click, prompt.submit],
|
63 |
+
partial(gr.update, interactive=False),
|
64 |
+
outputs=button,
|
65 |
+
).then(
|
66 |
+
generate_background,
|
67 |
+
inputs={prompt, model},
|
68 |
+
outputs=[background, output],
|
69 |
+
).then(
|
70 |
+
partial(gr.update, interactive=True),
|
71 |
+
outputs=button,
|
72 |
+
)
|
73 |
+
|
74 |
+
gr.on(
|
75 |
+
[text.submit, background.change, scale.change],
|
76 |
+
generate_output,
|
77 |
+
inputs={text, background, scale},
|
78 |
+
outputs=output,
|
79 |
+
)
|
80 |
+
|
81 |
|
82 |
if __name__ == "__main__":
|
83 |
demo.launch()
|