Spaces:
Running
Running
osanseviero
commited on
Commit
Β·
01d9fff
1
Parent(s):
07c3c3c
Minimalistic view?
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
4 |
-
|
5 |
img_to_text = gr.Interface.load("spaces/pharma/CLIP-Interrogator")
|
6 |
-
|
7 |
stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion")
|
8 |
|
9 |
def get_images(prompt):
|
@@ -13,94 +11,46 @@ def get_images(prompt):
|
|
13 |
def get_prompts(uploaded_image):
|
14 |
return img_to_text(uploaded_image)
|
15 |
|
16 |
-
|
17 |
with gr.Blocks() as demo:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
"""
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
#translate_img_directly = gr.Button("Translate your image now.", elem_id="translate_img")
|
40 |
-
|
41 |
-
with gr.Accordion(label="Stable Diffusion Settings", elem_id="sd_settings", visible=False):
|
42 |
-
with gr.Row():
|
43 |
-
guidance_scale = gr.Slider(2, 15, value = 7, label = 'Guidance Scale')
|
44 |
-
nb_iterations = gr.Slider(10, 50, value = 25, step = 1, label = 'Steps')
|
45 |
-
seed = gr.Slider(label = "Seed", minimum = 0, maximum = 2147483647, step = 1, randomize = True)
|
46 |
-
|
47 |
-
gr.Markdown(
|
48 |
-
"""
|
49 |
-
## Check what the model thinks of the image π
|
50 |
-
"""
|
51 |
-
)
|
52 |
-
|
53 |
-
with gr.Column():
|
54 |
-
img2text_output = gr.Textbox(
|
55 |
-
label="Convert your image to text!",
|
56 |
-
lines=4,
|
57 |
-
elem_id="translated"
|
58 |
-
)
|
59 |
-
with gr.Row():
|
60 |
-
clear_btn = gr.Button(value="Clear")
|
61 |
-
diffuse_btn = gr.Button(value="Diffuse it!", elem_id="diffuse_btn")
|
62 |
-
|
63 |
-
clear_btn.click(fn=lambda value: gr.update(value=""), inputs=clear_btn, outputs=img2text_output)
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
gr.Markdown("""
|
68 |
-
## 3. Diffuse it! π§βπ¨
|
69 |
-
"""
|
70 |
-
)
|
71 |
-
|
72 |
sd_output = gr.Gallery().style(grid=2, height="auto")
|
73 |
-
|
74 |
-
|
75 |
-
see_prompts.click(img_to_text,
|
76 |
-
inputs = input_img,
|
77 |
-
outputs = [
|
78 |
-
img2text_output
|
79 |
-
])
|
80 |
-
|
81 |
-
def translate_directly(img):
|
82 |
-
images = get_images(get_prompts(img))
|
83 |
-
return images
|
84 |
-
|
85 |
-
"""
|
86 |
-
translate_img_directly.click(translate_directly,
|
87 |
-
inputs = [
|
88 |
-
input_img
|
89 |
-
],
|
90 |
-
outputs = [
|
91 |
-
img2text_output,
|
92 |
-
sd_output
|
93 |
-
])
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
)
|
102 |
|
103 |
|
104 |
|
105 |
-
|
106 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
|
|
|
4 |
img_to_text = gr.Interface.load("spaces/pharma/CLIP-Interrogator")
|
|
|
5 |
stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion")
|
6 |
|
7 |
def get_images(prompt):
|
|
|
11 |
def get_prompts(uploaded_image):
|
12 |
return img_to_text(uploaded_image)
|
13 |
|
|
|
14 |
with gr.Blocks() as demo:
|
15 |
+
gr.Markdown(
|
16 |
+
"""
|
17 |
+
## Stable Diffusion Perception ππ
|
18 |
+
Input an image and see how the model perceives it! π
|
19 |
+
"""
|
20 |
+
)
|
21 |
+
|
22 |
+
with gr.Row():
|
23 |
+
with gr.Column():
|
24 |
+
input_img = gr.Image(type="filepath")
|
25 |
+
with gr.Row():
|
26 |
+
see_prompts = gr.Button("Check how your image prompts your model!", elem_id="check_btn_1")
|
27 |
+
|
28 |
+
with gr.Column():
|
29 |
+
img2text_output = gr.Textbox(
|
30 |
+
label="Convert your image to text!",
|
31 |
+
lines=4,
|
32 |
+
elem_id="translated"
|
33 |
)
|
34 |
+
with gr.Row():
|
35 |
+
diffuse_btn = gr.Button(value="Diffuse it!", elem_id="diffuse_btn")
|
36 |
+
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
sd_output = gr.Gallery().style(grid=2, height="auto")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
def translate_directly(img):
|
40 |
+
images = get_images(get_prompts(img))
|
41 |
+
return images
|
42 |
+
see_prompts.click(img_to_text,
|
43 |
+
inputs = input_img,
|
44 |
+
outputs = [
|
45 |
+
img2text_output
|
46 |
+
])
|
47 |
+
diffuse_btn.click(get_images,
|
48 |
+
inputs = [
|
49 |
+
img2text_output
|
50 |
+
],
|
51 |
+
outputs = sd_output
|
52 |
)
|
53 |
|
54 |
|
55 |
|
56 |
+
demo.launch()
|
|