Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
-
# If 'share_btn.py' is a custom module
|
|
|
|
| 5 |
# from share_btn import community_icon_html, loading_icon_html, share_js
|
| 6 |
|
| 7 |
# Load interfaces from Hugging Face Spaces
|
|
@@ -16,48 +17,95 @@ def get_images(prompt):
|
|
| 16 |
|
| 17 |
def get_prompts(prompt_text):
|
| 18 |
# Generate expanded prompts using the text_gen interface
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
css = '''
|
| 22 |
-
/* Your CSS styles remain unchanged */
|
| 23 |
.animate-spin {
|
| 24 |
animation: spin 1s linear infinite;
|
| 25 |
}
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
</div>
|
| 37 |
<p style="margin-bottom: 10px; font-size: 94%">
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
</p>
|
| 43 |
</div>
|
| 44 |
""")
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column():
|
| 47 |
-
input_text = gr.Textbox(
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
with gr.Column():
|
| 50 |
-
text_output = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 56 |
community_icon = gr.HTML("", visible=False)
|
| 57 |
loading_icon = gr.HTML("", visible=False)
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
see_prompts.click(
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
demo.launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# If 'share_btn.py' is a custom module and contains 'community_icon_html' and 'loading_icon_html',
|
| 5 |
+
# make sure it's available; otherwise, you can define these variables directly or remove them if not needed.
|
| 6 |
# from share_btn import community_icon_html, loading_icon_html, share_js
|
| 7 |
|
| 8 |
# Load interfaces from Hugging Face Spaces
|
|
|
|
| 17 |
|
| 18 |
def get_prompts(prompt_text):
|
| 19 |
# Generate expanded prompts using the text_gen interface
|
| 20 |
+
expanded_prompt = text_gen(prompt_text)
|
| 21 |
+
return expanded_prompt
|
| 22 |
|
| 23 |
css = '''
|
|
|
|
| 24 |
.animate-spin {
|
| 25 |
animation: spin 1s linear infinite;
|
| 26 |
}
|
| 27 |
+
@keyframes spin {
|
| 28 |
+
from {
|
| 29 |
+
transform: rotate(0deg);
|
| 30 |
+
}
|
| 31 |
+
to {
|
| 32 |
+
transform: rotate(360deg);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
#share-btn-container {
|
| 36 |
+
display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
| 37 |
+
}
|
| 38 |
+
#share-btn {
|
| 39 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
|
| 40 |
+
}
|
| 41 |
+
#share-btn * {
|
| 42 |
+
all: unset;
|
| 43 |
+
}
|
| 44 |
+
#share-btn-container div:nth-child(-n+2){
|
| 45 |
+
width: auto !important;
|
| 46 |
+
min-height: 0px !important;
|
| 47 |
+
}
|
| 48 |
+
#share-btn-container .wrap {
|
| 49 |
+
display: none !important;
|
| 50 |
+
}
|
| 51 |
+
a {text-decoration-line: underline;}
|
| 52 |
'''
|
| 53 |
|
| 54 |
with gr.Blocks(css=css) as demo:
|
| 55 |
gr.HTML("""
|
| 56 |
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
| 57 |
+
<div
|
| 58 |
+
style="
|
| 59 |
+
display: inline-flex;
|
| 60 |
+
align-items: center;
|
| 61 |
+
gap: 0.8rem;
|
| 62 |
+
font-size: 1.75rem;
|
| 63 |
+
"
|
| 64 |
+
>
|
| 65 |
+
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
|
| 66 |
+
Prompt Refinery
|
| 67 |
+
</h1>
|
| 68 |
</div>
|
| 69 |
<p style="margin-bottom: 10px; font-size: 94%">
|
| 70 |
+
🏭 Prompt Refinery generates variations of your prompt using
|
| 71 |
+
<a href="https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion" target="_blank">
|
| 72 |
+
MagicPrompt and Stable Diffusion
|
| 73 |
+
</a>
|
| 74 |
</p>
|
| 75 |
</div>
|
| 76 |
""")
|
| 77 |
with gr.Row():
|
| 78 |
with gr.Column():
|
| 79 |
+
input_text = gr.Textbox(
|
| 80 |
+
label="Input text prompt",
|
| 81 |
+
lines=2,
|
| 82 |
+
elem_id="input-text"
|
| 83 |
+
)
|
| 84 |
+
see_prompts = gr.Button("✍️ Expand my prompts")
|
| 85 |
with gr.Column():
|
| 86 |
+
text_output = gr.Textbox(
|
| 87 |
+
label="🏭 Expanded text prompts",
|
| 88 |
+
lines=8,
|
| 89 |
+
elem_id="translated"
|
| 90 |
+
)
|
| 91 |
diffuse_btn = gr.Button(value="🏭 Render Images for My Prompts")
|
| 92 |
with gr.Column(elem_id="generated-gallery"):
|
| 93 |
sd_output = gr.Gallery().style(grid=2, height="auto")
|
| 94 |
with gr.Group(elem_id="share-btn-container"):
|
| 95 |
+
# If you have HTML content for these icons, you can include it here
|
| 96 |
community_icon = gr.HTML("", visible=False)
|
| 97 |
loading_icon = gr.HTML("", visible=False)
|
| 98 |
|
| 99 |
+
# Connect the buttons to their respective functions
|
| 100 |
+
see_prompts.click(
|
| 101 |
+
fn=get_prompts,
|
| 102 |
+
inputs=[input_text],
|
| 103 |
+
outputs=[text_output]
|
| 104 |
+
)
|
| 105 |
+
diffuse_btn.click(
|
| 106 |
+
fn=get_images,
|
| 107 |
+
inputs=[text_output],
|
| 108 |
+
outputs=[sd_output, community_icon, loading_icon]
|
| 109 |
+
)
|
| 110 |
|
| 111 |
demo.launch(debug=True)
|