Update app.py
Browse files
app.py
CHANGED
@@ -153,69 +153,48 @@ def generate_text(prompt, max_length=100, temperature=0.7, top_k=50):
|
|
153 |
|
154 |
# Gradio interface
|
155 |
def gradio_generate(prompt, max_length, temperature, top_k):
|
156 |
-
|
|
|
|
|
|
|
|
|
157 |
|
158 |
# Custom CSS for the animation effect
|
159 |
-
|
160 |
<style>
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
overflow-y: auto;
|
169 |
-
background-color: #f9f9f9;
|
170 |
-
}
|
171 |
-
.blinking-cursor {
|
172 |
-
display: inline-block;
|
173 |
-
width: 10px;
|
174 |
-
height: 20px;
|
175 |
-
background-color: #333;
|
176 |
-
animation: blink 0.7s infinite;
|
177 |
-
}
|
178 |
-
@keyframes blink {
|
179 |
-
0% { opacity: 0; }
|
180 |
-
50% { opacity: 1; }
|
181 |
-
100% { opacity: 0; }
|
182 |
-
}
|
183 |
</style>
|
184 |
"""
|
185 |
|
186 |
-
#
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
outputs=gr.HTML(label="Generated Text"),
|
213 |
-
title="Animated GPT Text Generator",
|
214 |
-
description="Enter a prompt and adjust parameters to generate text using a fine-tuned GPT model.",
|
215 |
-
css=custom_css,
|
216 |
-
js=js_code,
|
217 |
-
live=True
|
218 |
-
)
|
219 |
-
|
220 |
-
# Launch the app
|
221 |
-
iface.launch()
|
|
|
153 |
|
154 |
# Gradio interface
|
155 |
def gradio_generate(prompt, max_length, temperature, top_k):
|
156 |
+
output = ""
|
157 |
+
for token in generate_text(prompt, max_length, temperature, top_k):
|
158 |
+
output += token
|
159 |
+
time.sleep(0.05) # Simulate typing effect
|
160 |
+
yield output
|
161 |
|
162 |
# Custom CSS for the animation effect
|
163 |
+
css = """
|
164 |
<style>
|
165 |
+
body { background-color: #1e1e1e; color: #ffffff; font-family: Arial, sans-serif; }
|
166 |
+
.container { max-width: 800px; margin: 0 auto; padding: 20px; }
|
167 |
+
.header { text-align: center; margin-bottom: 30px; }
|
168 |
+
.chat-box { background-color: #2a2a2a; border-radius: 10px; padding: 20px; margin-bottom: 20px; }
|
169 |
+
.user-input { background-color: #3a3a3a; border: none; color: #ffffff; padding: 10px; border-radius: 5px; width: 100%; }
|
170 |
+
.generate-btn { background-color: #5465ff; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; }
|
171 |
+
.output-box { background-color: #2a2a2a; border-radius: 10px; padding: 20px; margin-top: 20px; min-height: 100px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
</style>
|
173 |
"""
|
174 |
|
175 |
+
# 6. Gradio App Definition
|
176 |
+
with gr.Blocks(css=css) as demo:
|
177 |
+
gr.HTML("<div class='header'><h1>🌟 GPT-2 Text Generator</h1></div>")
|
178 |
+
|
179 |
+
with gr.Row():
|
180 |
+
with gr.Column(scale=3):
|
181 |
+
prompt = gr.Textbox(placeholder="Enter your prompt here...", label="Prompt", elem_classes="user-input")
|
182 |
+
with gr.Column(scale=1):
|
183 |
+
generate_btn = gr.Button("Generate", elem_classes="generate-btn")
|
184 |
+
|
185 |
+
with gr.Row():
|
186 |
+
max_length = gr.Slider(minimum=20, maximum=500, value=100, step=1, label="Max Length")
|
187 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
|
188 |
+
top_k = gr.Slider(minimum=1, maximum=100, value=50, step=1, label="Top-k")
|
189 |
+
|
190 |
+
output = gr.Markdown(elem_classes="output-box")
|
191 |
+
|
192 |
+
generate_btn.click(
|
193 |
+
gradio_generate,
|
194 |
+
inputs=[prompt, max_length, temperature, top_k],
|
195 |
+
outputs=output
|
196 |
+
)
|
197 |
+
|
198 |
+
# 7. Launch the app
|
199 |
+
if __name__ == "__main__":
|
200 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|