Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
-
import gradio as grad
|
| 3 |
-
|
|
|
|
| 4 |
|
|
|
|
| 5 |
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
| 6 |
with open("ideas.txt", "r") as f:
|
| 7 |
line = f.readlines()
|
| 8 |
|
| 9 |
-
|
| 10 |
def generate(starting_text):
|
| 11 |
for count in range(4):
|
| 12 |
seed = random.randint(100, 1000000)
|
|
@@ -33,27 +34,144 @@ def generate(starting_text):
|
|
| 33 |
if count == 4:
|
| 34 |
return response_end
|
| 35 |
|
| 36 |
-
|
| 37 |
-
txt = grad.Textbox(lines=1, label="Initial Text", placeholder="English Text here")
|
| 38 |
-
out = grad.Textbox(lines=4, label="Generated Prompts")
|
| 39 |
-
|
| 40 |
examples = []
|
| 41 |
for x in range(8):
|
| 42 |
examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
cache_examples=False,
|
| 57 |
-
theme="default").launch(enable_queue=True, debug=True)
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline, set_seed
|
| 2 |
+
import gradio as grad
|
| 3 |
+
import random
|
| 4 |
+
import re
|
| 5 |
|
| 6 |
+
# Model initialization
|
| 7 |
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
| 8 |
with open("ideas.txt", "r") as f:
|
| 9 |
line = f.readlines()
|
| 10 |
|
|
|
|
| 11 |
def generate(starting_text):
|
| 12 |
for count in range(4):
|
| 13 |
seed = random.randint(100, 1000000)
|
|
|
|
| 34 |
if count == 4:
|
| 35 |
return response_end
|
| 36 |
|
| 37 |
+
# Example generation
|
|
|
|
|
|
|
|
|
|
| 38 |
examples = []
|
| 39 |
for x in range(8):
|
| 40 |
examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())
|
| 41 |
|
| 42 |
+
# Custom CSS
|
| 43 |
+
custom_css = """
|
| 44 |
+
.gradio-container {
|
| 45 |
+
background: linear-gradient(145deg, #2a2a2a, #3a3a3a);
|
| 46 |
+
border-radius: 20px;
|
| 47 |
+
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
| 48 |
+
backdrop-filter: blur(4px);
|
| 49 |
+
-webkit-backdrop-filter: blur(4px);
|
| 50 |
+
border: 1px solid rgba(255, 255, 255, 0.18);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.input-textbox, .output-textbox {
|
| 54 |
+
background: rgba(255, 255, 255, 0.1) !important;
|
| 55 |
+
border-radius: 15px !important;
|
| 56 |
+
padding: 20px !important;
|
| 57 |
+
box-shadow: 0 4px 15px rgba(0,0,0,0.2);
|
| 58 |
+
transform: perspective(1000px) rotateX(2deg);
|
| 59 |
+
transition: all 0.3s ease;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.input-textbox:hover, .output-textbox:hover {
|
| 63 |
+
transform: perspective(1000px) rotateX(0deg);
|
| 64 |
+
box-shadow: 0 6px 20px rgba(0,0,0,0.3);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.example-btn {
|
| 68 |
+
background: linear-gradient(45deg, #6b46c1, #805ad5) !important;
|
| 69 |
+
border-radius: 10px !important;
|
| 70 |
+
border: none !important;
|
| 71 |
+
color: white !important;
|
| 72 |
+
transform: translateY(0);
|
| 73 |
+
transition: all 0.2s ease;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
.example-btn:hover {
|
| 77 |
+
transform: translateY(-2px);
|
| 78 |
+
box-shadow: 0 5px 15px rgba(107, 70, 193, 0.4);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.title-text {
|
| 82 |
+
font-size: 2.5em !important;
|
| 83 |
+
background: linear-gradient(45deg, #6b46c1, #805ad5);
|
| 84 |
+
-webkit-background-clip: text;
|
| 85 |
+
-webkit-text-fill-color: transparent;
|
| 86 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.container {
|
| 90 |
+
animation: float 6s ease-in-out infinite;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
@keyframes float {
|
| 94 |
+
0% { transform: translateY(0px); }
|
| 95 |
+
50% { transform: translateY(-20px); }
|
| 96 |
+
100% { transform: translateY(0px); }
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.submit-btn {
|
| 100 |
+
background: linear-gradient(45deg, #6b46c1, #805ad5) !important;
|
| 101 |
+
border-radius: 15px !important;
|
| 102 |
+
padding: 10px 20px !important;
|
| 103 |
+
font-weight: bold !important;
|
| 104 |
+
transform: translateY(0);
|
| 105 |
+
transition: all 0.3s ease;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.submit-btn:hover {
|
| 109 |
+
transform: translateY(-3px);
|
| 110 |
+
box-shadow: 0 10px 20px rgba(107, 70, 193, 0.3);
|
| 111 |
+
}
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
# Interface content
|
| 115 |
+
title = """
|
| 116 |
+
<div class="title-text">
|
| 117 |
+
Stable Diffusion Prompt Generator
|
| 118 |
+
</div>
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
description = """
|
| 122 |
+
<div style="padding: 20px; background: rgba(255,255,255,0.1); border-radius: 15px; margin: 10px 0;">
|
| 123 |
+
This is a demo of the model series: "MagicPrompt", aimed at Stable Diffusion.
|
| 124 |
+
To use it, simply submit your text or click on one of the examples.
|
| 125 |
+
<br><br>
|
| 126 |
+
<a href="https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion"
|
| 127 |
+
style="color: #805ad5; text-decoration: none; font-weight: bold;">
|
| 128 |
+
Learn more about the model →
|
| 129 |
+
</a>
|
| 130 |
+
</div>
|
| 131 |
+
"""
|
| 132 |
|
| 133 |
+
article = """
|
| 134 |
+
<div class="container" style="text-align: center; padding: 20px;">
|
| 135 |
+
<img src='https://visitor-badge.glitch.me/badge?page_id=_Stable_Diffusion' alt='visitor badge'/>
|
| 136 |
+
<div style="margin-top: 20px; color: #805ad5;">
|
| 137 |
+
✨ Created with AI Magic ✨
|
| 138 |
+
</div>
|
| 139 |
+
</div>
|
| 140 |
+
"""
|
|
|
|
|
|
|
| 141 |
|
| 142 |
+
# Gradio Interface
|
| 143 |
+
interface = grad.Interface(
|
| 144 |
+
fn=generate,
|
| 145 |
+
inputs=[
|
| 146 |
+
grad.Textbox(
|
| 147 |
+
lines=1,
|
| 148 |
+
label="Initial Text",
|
| 149 |
+
placeholder="Enter your prompt here...",
|
| 150 |
+
elem_classes="input-textbox"
|
| 151 |
+
)
|
| 152 |
+
],
|
| 153 |
+
outputs=[
|
| 154 |
+
grad.Textbox(
|
| 155 |
+
lines=4,
|
| 156 |
+
label="Generated Prompts",
|
| 157 |
+
elem_classes="output-textbox"
|
| 158 |
+
)
|
| 159 |
+
],
|
| 160 |
+
examples=examples,
|
| 161 |
+
title=title,
|
| 162 |
+
description=description,
|
| 163 |
+
article=article,
|
| 164 |
+
allow_flagging='never',
|
| 165 |
+
cache_examples=False,
|
| 166 |
+
css=custom_css,
|
| 167 |
+
theme=grad.themes.Base().set(
|
| 168 |
+
primary_hue="purple",
|
| 169 |
+
secondary_hue="purple",
|
| 170 |
+
neutral_hue="gray",
|
| 171 |
+
radius_size="lg",
|
| 172 |
+
shadow_size="lg"
|
| 173 |
+
)
|
| 174 |
+
)
|
| 175 |
|
| 176 |
+
# Launch the interface
|
| 177 |
+
interface.launch(enable_queue=True, debug=True)
|