Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,67 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
return
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
with gr.Blocks() as demo:
|
| 26 |
gr.Markdown(
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
)
|
| 34 |
gr.LoginButton()
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
|
| 4 |
+
from huggingface_hub import list_liked_repos
|
| 5 |
+
from diffusers import DiffusionPipeline
|
| 6 |
|
| 7 |
+
def image_mod(prompt: str, model: str, image_0: gr.Image, image_1: gr.Image) -> list[gr.Image]:
|
| 8 |
+
images = [image_0, image_1]
|
| 9 |
+
for i, diffusion_model in enumerate(model):
|
| 10 |
+
pipeline = DiffusionPipeline.from_pretrained(pretrained_model_name_or_path=diffusion_model, device_map="auto")
|
| 11 |
+
images[i] = pipeline(prompt).images[0]
|
| 12 |
+
return images
|
| 13 |
|
| 14 |
+
def get_liked_models(username: str) -> list:
|
| 15 |
+
likes = list_liked_repos(username)
|
| 16 |
+
# filter if the models are diffusion models
|
| 17 |
+
return likes.models
|
| 18 |
|
| 19 |
+
|
| 20 |
+
def get_dropdown_for_huggingface(profile: gr.OAuthProfile):
|
| 21 |
+
return gr.Dropdown(
|
| 22 |
+
choices=get_liked_models(profile.username),
|
| 23 |
+
multiselect=True,
|
| 24 |
+
max_choices=2,
|
| 25 |
+
label="Select a Model from Hugginface",
|
| 26 |
+
info="Select up to two models to compare. If you want to see more models populated in the dropdown, just like a model on huggingface! The dropdown is refreshed every minute.",
|
| 27 |
+
every=60,
|
| 28 |
+
visible=True
|
| 29 |
+
)
|
| 30 |
|
| 31 |
|
| 32 |
+
def change_model(choice):
|
| 33 |
+
images = [gr.Image(visible=False), gr.Image(visible=False)]
|
| 34 |
+
for i, model in enumerate(choice):
|
| 35 |
+
images[i] = gr.Image(label=model, visible=True, interactive=False)
|
| 36 |
+
|
| 37 |
+
return images
|
| 38 |
+
|
| 39 |
with gr.Blocks() as demo:
|
| 40 |
gr.Markdown(
|
| 41 |
+
"""
|
| 42 |
+
**Comparing Stable Diffusion Models**
|
| 43 |
+
|
| 44 |
+
See https://huggingface.co/docs/diffusers/main/en/api/diffusion_pipeline
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
""")
|
| 48 |
gr.LoginButton()
|
| 49 |
+
dropdown = gr.Dropdown(visible=False)
|
| 50 |
+
demo.load(get_dropdown_for_huggingface, inputs=None, outputs=dropdown)
|
| 51 |
+
|
| 52 |
+
textbox = gr.Textbox(label="Prompt for Image Generation")
|
| 53 |
+
|
| 54 |
+
with gr.Row() as row:
|
| 55 |
+
image_0 = gr.Image(visible=False)
|
| 56 |
+
image_1 = gr.Image(visible=False)
|
| 57 |
+
dropdown.change(
|
| 58 |
+
fn=change_model,
|
| 59 |
+
inputs=dropdown,
|
| 60 |
+
outputs=[image_0, image_1]
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
textbox.submit(
|
| 64 |
+
image_mod, [textbox, dropdown, image_0, image_1], [image_0, image_1]
|
| 65 |
+
)
|
| 66 |
|
| 67 |
demo.launch()
|