|
import gradio as gr |
|
import os |
|
|
|
|
|
|
|
|
|
|
|
text_gen = gr.Interface.load(name="spaces/Gustavosta/MagicPrompt-Stable-Diffusion") |
|
stable_diffusion = gr.Interface.load(name="spaces/runwayml/stable-diffusion-v1-5") |
|
|
|
def get_images(prompt): |
|
|
|
sd_output = stable_diffusion(prompt) |
|
|
|
return sd_output, gr.update(visible=True), gr.update(visible=True) |
|
|
|
def get_prompts(prompt_text): |
|
|
|
return text_gen(prompt_text) |
|
|
|
css = ''' |
|
/* Your CSS styles remain unchanged */ |
|
.animate-spin { |
|
animation: spin 1s linear infinite; |
|
} |
|
/* ... rest of the CSS ... */ |
|
''' |
|
|
|
with gr.Blocks(css=css) as demo: |
|
gr.HTML(""" |
|
<div style="text-align: center; max-width: 700px; margin: 0 auto;"> |
|
<div style="display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;"> |
|
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;"> |
|
Prompt Refinery |
|
</h1> |
|
</div> |
|
<p style="margin-bottom: 10px; font-size: 94%"> |
|
🏭 Prompt Refinery generates variations of your prompt using |
|
<a href="https://huggingface.co./spaces/Gustavosta/MagicPrompt-Stable-Diffusion" target="_blank"> |
|
MagicPrompt and Stable Diffusion |
|
</a> |
|
</p> |
|
</div> |
|
""") |
|
with gr.Row(): |
|
with gr.Column(): |
|
input_text = gr.Textbox(label="Input text prompt", lines=2, elem_id="input-text") |
|
see_prompts = gr.Button("✍️Expand my prompts") |
|
with gr.Column(): |
|
text_output = gr.Textbox(label="🏭 Expanded text prompts", lines=8, elem_id="translated") |
|
diffuse_btn = gr.Button(value="🏭 Render Images for My Prompts") |
|
with gr.Column(elem_id="generated-gallery"): |
|
sd_output = gr.Gallery().style(grid=2, height="auto") |
|
with gr.Group(elem_id="share-btn-container"): |
|
|
|
community_icon = gr.HTML("", visible=False) |
|
loading_icon = gr.HTML("", visible=False) |
|
|
|
|
|
see_prompts.click(get_prompts, inputs=[input_text], outputs=[text_output]) |
|
diffuse_btn.click(get_images, inputs=[text_output], outputs=[sd_output, community_icon, loading_icon]) |
|
|
|
demo.launch(debug=True) |
|
|