Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
-
from ominicontrol import generate_image
|
| 4 |
import os
|
| 5 |
|
| 6 |
|
|
@@ -111,15 +111,62 @@ def gradio_interface():
|
|
| 111 |
show_progress="hidden",
|
| 112 |
)
|
| 113 |
|
| 114 |
-
btn = gr.Button("Generate Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
with gr.Column(elem_classes="outputPanel"):
|
| 117 |
-
|
| 118 |
type="pil",
|
| 119 |
-
width=
|
| 120 |
-
height=
|
| 121 |
label="Output Image",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
hint = gr.Markdown(
|
| 124 |
"""
|
| 125 |
<div style="text-align: center; width: 100%;">
|
|
@@ -134,19 +181,7 @@ def gradio_interface():
|
|
| 134 |
hint,
|
| 135 |
)
|
| 136 |
|
| 137 |
-
with gr.Row():
|
| 138 |
-
examples = gr.Examples(
|
| 139 |
-
examples=[
|
| 140 |
-
["examples/DistractedBoyfriend.webp", styles[0]],
|
| 141 |
-
["examples/steve.webp", styles[0]],
|
| 142 |
-
["examples/oiiai.png", styles[1]],
|
| 143 |
-
["examples/doge.jpg", styles[1]],
|
| 144 |
-
["examples/breakingbad.jpg", styles[2]],
|
| 145 |
-
["examples/PulpFiction.jpg", styles[3]],
|
| 146 |
-
],
|
| 147 |
-
inputs=[original_image, style],
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
btn.click(
|
| 151 |
fn=infer,
|
| 152 |
inputs=[
|
|
@@ -159,7 +194,10 @@ def gradio_interface():
|
|
| 159 |
seed,
|
| 160 |
steps,
|
| 161 |
],
|
| 162 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 163 |
)
|
| 164 |
|
| 165 |
return demo
|
|
@@ -178,7 +216,7 @@ def infer(
|
|
| 178 |
print(
|
| 179 |
f"Style: {style}, Inference Mode: {inference_mode}, Image Guidance: {image_guidance}, Image Ratio: {image_ratio}, Use Random Seed: {use_random_seed}, Seed: {seed}"
|
| 180 |
)
|
| 181 |
-
result_image = generate_image(
|
| 182 |
image=original_image,
|
| 183 |
style=style,
|
| 184 |
inference_mode=inference_mode,
|
|
@@ -188,7 +226,7 @@ def infer(
|
|
| 188 |
seed=seed,
|
| 189 |
steps=steps,
|
| 190 |
)
|
| 191 |
-
return result_image
|
| 192 |
|
| 193 |
|
| 194 |
if USE_ZERO_GPU:
|
|
@@ -196,4 +234,4 @@ if USE_ZERO_GPU:
|
|
| 196 |
|
| 197 |
if __name__ == "__main__":
|
| 198 |
demo = gradio_interface()
|
| 199 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
+
from ominicontrol import generate_image, vote_feedback
|
| 4 |
import os
|
| 5 |
|
| 6 |
|
|
|
|
| 111 |
show_progress="hidden",
|
| 112 |
)
|
| 113 |
|
| 114 |
+
btn = gr.Button("Generate Image", variant="primary")
|
| 115 |
+
|
| 116 |
+
with gr.Accordion("🏞️ Examples", open=True) as advanced_settings:
|
| 117 |
+
examples = gr.Examples(
|
| 118 |
+
examples=[
|
| 119 |
+
["examples/DistractedBoyfriend.webp", styles[0]],
|
| 120 |
+
["examples/steve.webp", styles[0]],
|
| 121 |
+
["examples/oiiai.png", styles[1]],
|
| 122 |
+
["examples/doge.jpg", styles[1]],
|
| 123 |
+
["examples/breakingbad.jpg", styles[2]],
|
| 124 |
+
["examples/PulpFiction.jpg", styles[3]],
|
| 125 |
+
],
|
| 126 |
+
inputs=[original_image, style],
|
| 127 |
+
)
|
| 128 |
|
| 129 |
with gr.Column(elem_classes="outputPanel"):
|
| 130 |
+
output_image = gr.Image(
|
| 131 |
type="pil",
|
| 132 |
+
width=600,
|
| 133 |
+
height=600,
|
| 134 |
label="Output Image",
|
| 135 |
+
interactive=False,
|
| 136 |
+
sources=None,
|
| 137 |
+
)
|
| 138 |
+
inference_id = gr.Textbox(
|
| 139 |
+
visible=False,
|
| 140 |
+
interactive=False,
|
| 141 |
)
|
| 142 |
+
|
| 143 |
+
# Feedback buttons
|
| 144 |
+
with gr.Column(visible=False) as feedback:
|
| 145 |
+
gr.Markdown(
|
| 146 |
+
"""
|
| 147 |
+
Your feedback improves the model! Please let us know how you feel about the generated image.
|
| 148 |
+
""",
|
| 149 |
+
)
|
| 150 |
+
with gr.Row() as feedback_buttons:
|
| 151 |
+
upvote = gr.Button("👍 I like it", variant="primary")
|
| 152 |
+
downvote = gr.Button("👎 It looks bad")
|
| 153 |
+
|
| 154 |
+
def feedback_func(feedback):
|
| 155 |
+
def func(inputs):
|
| 156 |
+
print(f"Feedback: {feedback}, Inference ID: {inputs}")
|
| 157 |
+
vote_feedback(log_id=inputs, feedback=feedback)
|
| 158 |
+
# Here you can add your feedback logging logic
|
| 159 |
+
return gr.update(visible=False)
|
| 160 |
+
|
| 161 |
+
return func
|
| 162 |
+
|
| 163 |
+
upvote.click(feedback_func("1"), inference_id, feedback)
|
| 164 |
+
downvote.click(feedback_func("0"), inference_id, feedback)
|
| 165 |
+
|
| 166 |
+
inference_id.change(
|
| 167 |
+
lambda x: gr.update(visible=True), output_image, feedback
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
hint = gr.Markdown(
|
| 171 |
"""
|
| 172 |
<div style="text-align: center; width: 100%;">
|
|
|
|
| 181 |
hint,
|
| 182 |
)
|
| 183 |
|
| 184 |
+
# with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
btn.click(
|
| 186 |
fn=infer,
|
| 187 |
inputs=[
|
|
|
|
| 194 |
seed,
|
| 195 |
steps,
|
| 196 |
],
|
| 197 |
+
outputs=[
|
| 198 |
+
output_image,
|
| 199 |
+
inference_id,
|
| 200 |
+
],
|
| 201 |
)
|
| 202 |
|
| 203 |
return demo
|
|
|
|
| 216 |
print(
|
| 217 |
f"Style: {style}, Inference Mode: {inference_mode}, Image Guidance: {image_guidance}, Image Ratio: {image_ratio}, Use Random Seed: {use_random_seed}, Seed: {seed}"
|
| 218 |
)
|
| 219 |
+
result_image, inference_id = generate_image(
|
| 220 |
image=original_image,
|
| 221 |
style=style,
|
| 222 |
inference_mode=inference_mode,
|
|
|
|
| 226 |
seed=seed,
|
| 227 |
steps=steps,
|
| 228 |
)
|
| 229 |
+
return result_image, inference_id
|
| 230 |
|
| 231 |
|
| 232 |
if USE_ZERO_GPU:
|
|
|
|
| 234 |
|
| 235 |
if __name__ == "__main__":
|
| 236 |
demo = gradio_interface()
|
| 237 |
+
demo.launch(server_name="0.0.0.0")
|