Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ from torch.nn import functional as F
|
|
9 |
import tiktoken
|
10 |
import gradio as gr
|
11 |
import asyncio
|
|
|
|
|
12 |
|
13 |
# Add the post-processing function here
|
14 |
def post_process_text(text):
|
@@ -185,35 +187,110 @@ async def gradio_generate(prompt, max_length, temperature, top_k):
|
|
185 |
yield output
|
186 |
|
187 |
# Custom CSS for the animation effect
|
|
|
|
|
|
|
|
|
|
|
188 |
css = """
|
189 |
<style>
|
190 |
-
body {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
.container { max-width: 800px; margin: 0 auto; padding: 20px; }
|
192 |
-
.header {
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
</style>
|
198 |
"""
|
199 |
|
200 |
with gr.Blocks(css=css) as demo:
|
201 |
-
gr.HTML("<div class='header'><h1>π
|
202 |
|
203 |
with gr.Row():
|
204 |
with gr.Column(scale=3):
|
205 |
prompt = gr.Textbox(
|
206 |
-
placeholder="
|
207 |
-
label="Story
|
208 |
elem_classes="user-input"
|
209 |
)
|
210 |
with gr.Column(scale=1):
|
211 |
-
generate_btn = gr.Button("
|
212 |
|
213 |
with gr.Row():
|
214 |
-
max_length = gr.Slider(minimum=50, maximum=500, value=432, step=1, label="
|
215 |
-
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.8, step=0.1, label="
|
216 |
-
top_k = gr.Slider(minimum=1, maximum=100, value=40, step=1, label="
|
217 |
|
218 |
output = gr.Markdown(elem_classes="output-box")
|
219 |
|
@@ -223,6 +300,11 @@ with gr.Blocks(css=css) as demo:
|
|
223 |
outputs=output
|
224 |
)
|
225 |
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
if __name__ == "__main__":
|
228 |
demo.launch()
|
|
|
9 |
import tiktoken
|
10 |
import gradio as gr
|
11 |
import asyncio
|
12 |
+
import gradio as gr
|
13 |
+
import asyncio
|
14 |
|
15 |
# Add the post-processing function here
|
16 |
def post_process_text(text):
|
|
|
187 |
yield output
|
188 |
|
189 |
# Custom CSS for the animation effect
|
190 |
+
import gradio as gr
|
191 |
+
import asyncio
|
192 |
+
|
193 |
+
# Your existing imports and model code here...
|
194 |
+
|
195 |
css = """
|
196 |
<style>
|
197 |
+
body {
|
198 |
+
background-color: #0f1624;
|
199 |
+
color: #e0e0e0;
|
200 |
+
font-family: 'Courier New', monospace;
|
201 |
+
background-image:
|
202 |
+
radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px),
|
203 |
+
radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px),
|
204 |
+
radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px),
|
205 |
+
radial-gradient(rgba(255,255,255,.4), rgba(255,255,255,.1) 2px, transparent 30px);
|
206 |
+
background-size: 550px 550px, 350px 350px, 250px 250px, 150px 150px;
|
207 |
+
background-position: 0 0, 40px 60px, 130px 270px, 70px 100px;
|
208 |
+
animation: backgroundScroll 60s linear infinite;
|
209 |
+
}
|
210 |
+
@keyframes backgroundScroll {
|
211 |
+
0% { background-position: 0 0, 40px 60px, 130px 270px, 70px 100px; }
|
212 |
+
100% { background-position: 550px 550px, 590px 610px, 680px 820px, 620px 650px; }
|
213 |
+
}
|
214 |
.container { max-width: 800px; margin: 0 auto; padding: 20px; }
|
215 |
+
.header {
|
216 |
+
text-align: center;
|
217 |
+
margin-bottom: 30px;
|
218 |
+
font-family: 'Copperplate', fantasy;
|
219 |
+
color: #ffd700;
|
220 |
+
text-shadow: 0 0 10px #ffd700, 0 0 20px #ffd700, 0 0 30px #ffd700;
|
221 |
+
}
|
222 |
+
.chat-box {
|
223 |
+
background-color: rgba(42, 42, 42, 0.7);
|
224 |
+
border-radius: 15px;
|
225 |
+
padding: 20px;
|
226 |
+
margin-bottom: 20px;
|
227 |
+
box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
|
228 |
+
}
|
229 |
+
.user-input {
|
230 |
+
background-color: rgba(58, 58, 58, 0.8);
|
231 |
+
border: 2px solid #ffd700;
|
232 |
+
color: #ffffff;
|
233 |
+
padding: 10px;
|
234 |
+
border-radius: 5px;
|
235 |
+
width: 100%;
|
236 |
+
transition: all 0.3s ease;
|
237 |
+
}
|
238 |
+
.user-input:focus {
|
239 |
+
box-shadow: 0 0 15px #ffd700;
|
240 |
+
}
|
241 |
+
.generate-btn {
|
242 |
+
background-color: #ffd700;
|
243 |
+
color: #0f1624;
|
244 |
+
border: none;
|
245 |
+
padding: 10px 20px;
|
246 |
+
border-radius: 5px;
|
247 |
+
cursor: pointer;
|
248 |
+
font-weight: bold;
|
249 |
+
transition: all 0.3s ease;
|
250 |
+
}
|
251 |
+
.generate-btn:hover {
|
252 |
+
background-color: #ffec8b;
|
253 |
+
transform: scale(1.05);
|
254 |
+
}
|
255 |
+
.output-box {
|
256 |
+
background-color: rgba(42, 42, 42, 0.7);
|
257 |
+
border-radius: 15px;
|
258 |
+
padding: 20px;
|
259 |
+
margin-top: 20px;
|
260 |
+
min-height: 100px;
|
261 |
+
border: 1px solid #ffd700;
|
262 |
+
white-space: pre-wrap;
|
263 |
+
font-family: 'Georgia', serif;
|
264 |
+
line-height: 1.6;
|
265 |
+
box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.3);
|
266 |
+
}
|
267 |
+
.gr-slider {
|
268 |
+
--slider-color: #ffd700;
|
269 |
+
}
|
270 |
+
.gr-box {
|
271 |
+
border-color: #ffd700;
|
272 |
+
background-color: rgba(42, 42, 42, 0.7);
|
273 |
+
}
|
274 |
</style>
|
275 |
"""
|
276 |
|
277 |
with gr.Blocks(css=css) as demo:
|
278 |
+
gr.HTML("<div class='header'><h1>π Enchanted Tales Generator π</h1></div>")
|
279 |
|
280 |
with gr.Row():
|
281 |
with gr.Column(scale=3):
|
282 |
prompt = gr.Textbox(
|
283 |
+
placeholder="Begin your magical journey here (e.g., 'In a realm beyond the mists of time...')",
|
284 |
+
label="Story Incantation",
|
285 |
elem_classes="user-input"
|
286 |
)
|
287 |
with gr.Column(scale=1):
|
288 |
+
generate_btn = gr.Button("Weave the Tale", elem_classes="generate-btn")
|
289 |
|
290 |
with gr.Row():
|
291 |
+
max_length = gr.Slider(minimum=50, maximum=500, value=432, step=1, label="Scroll Length")
|
292 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.8, step=0.1, label="Magical Intensity")
|
293 |
+
top_k = gr.Slider(minimum=1, maximum=100, value=40, step=1, label="Arcane Diversity")
|
294 |
|
295 |
output = gr.Markdown(elem_classes="output-box")
|
296 |
|
|
|
300 |
outputs=output
|
301 |
)
|
302 |
|
303 |
+
gr.HTML("""
|
304 |
+
<div style="text-align: center; margin-top: 20px; font-style: italic; color: #ffd700;">
|
305 |
+
"In the realm of imagination, every word is a spell, every sentence a charm."
|
306 |
+
</div>
|
307 |
+
""")
|
308 |
|
309 |
if __name__ == "__main__":
|
310 |
demo.launch()
|