Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
# If 'share_btn.py' is a custom module, ensure it's available; otherwise, comment out or remove these imports
|
5 |
+
# from share_btn import community_icon_html, loading_icon_html, share_js
|
6 |
+
|
7 |
+
# Load interfaces from Hugging Face Spaces
|
8 |
+
text_gen = gr.Interface.load(name="spaces/Gustavosta/MagicPrompt-Stable-Diffusion")
|
9 |
+
stable_diffusion = gr.Interface.load(name="spaces/runwayml/stable-diffusion-v1-5")
|
10 |
+
|
11 |
+
def get_images(prompt):
|
12 |
+
# Call the stable_diffusion interface with the prompt
|
13 |
+
sd_output = stable_diffusion(prompt)
|
14 |
+
# Return the output images and update the visibility of icons
|
15 |
+
return sd_output, gr.update(visible=True), gr.update(visible=True)
|
16 |
+
|
17 |
+
def get_prompts(prompt_text):
|
18 |
+
# Generate expanded prompts using the text_gen interface
|
19 |
+
return text_gen(prompt_text)
|
20 |
+
|
21 |
+
css = '''
|
22 |
+
/* Your CSS styles remain unchanged */
|
23 |
+
.animate-spin {
|
24 |
+
animation: spin 1s linear infinite;
|
25 |
+
}
|
26 |
+
/* ... rest of the CSS ... */
|
27 |
+
'''
|
28 |
+
|
29 |
+
with gr.Blocks(css=css) as demo:
|
30 |
+
gr.HTML("""
|
31 |
+
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
32 |
+
<div style="display: inline-flex; align-items: center; gap: 0.8rem; font-size: 1.75rem;">
|
33 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
|
34 |
+
Prompt Refinery
|
35 |
+
</h1>
|
36 |
+
</div>
|
37 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
38 |
+
🏭 Prompt Refinery generates variations of your prompt using
|
39 |
+
<a href="https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion" target="_blank">
|
40 |
+
MagicPrompt and Stable Diffusion
|
41 |
+
</a>
|
42 |
+
</p>
|
43 |
+
</div>
|
44 |
+
""")
|
45 |
+
with gr.Row():
|
46 |
+
with gr.Column():
|
47 |
+
input_text = gr.Textbox(label="Input text prompt", lines=2, elem_id="input-text")
|
48 |
+
see_prompts = gr.Button("✍️Expand my prompts")
|
49 |
+
with gr.Column():
|
50 |
+
text_output = gr.Textbox(label="🏭 Expanded text prompts", lines=8, elem_id="translated")
|
51 |
+
diffuse_btn = gr.Button(value="🏭 Render Images for My Prompts")
|
52 |
+
with gr.Column(elem_id="generated-gallery"):
|
53 |
+
sd_output = gr.Gallery().style(grid=2, height="auto")
|
54 |
+
with gr.Group(elem_id="share-btn-container"):
|
55 |
+
# Replace the content of community_icon_html and loading_icon_html with actual HTML or leave empty
|
56 |
+
community_icon = gr.HTML("", visible=False)
|
57 |
+
loading_icon = gr.HTML("", visible=False)
|
58 |
+
|
59 |
+
# Define the interactions without 'api_name', which is deprecated
|
60 |
+
see_prompts.click(get_prompts, inputs=[input_text], outputs=[text_output])
|
61 |
+
diffuse_btn.click(get_images, inputs=[text_output], outputs=[sd_output, community_icon, loading_icon])
|
62 |
+
|
63 |
+
demo.launch(debug=True)
|