Update app.py
Browse files
app.py
CHANGED
|
@@ -264,11 +264,8 @@ class SpaceInferenceEngine:
|
|
| 264 |
generated_text += token_str
|
| 265 |
yield generated_text
|
| 266 |
|
| 267 |
-
# Optional: Stop generation if needed
|
| 268 |
-
# if new_token_id == self.tokenizer.token_to_id("<EOS>"): break
|
| 269 |
-
|
| 270 |
# ============================================================================
|
| 271 |
-
# 3. GRADIO INTERFACE
|
| 272 |
# ============================================================================
|
| 273 |
|
| 274 |
# Initialize engine globally
|
|
@@ -288,29 +285,53 @@ def predict(prompt, max_tokens, temperature, top_k):
|
|
| 288 |
):
|
| 289 |
yield current_text
|
| 290 |
|
| 291 |
-
# Custom CSS
|
| 292 |
custom_css = """
|
| 293 |
-
#
|
|
|
|
| 294 |
"""
|
| 295 |
|
| 296 |
-
with gr.
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
gr.
|
| 300 |
-
|
| 301 |
-
gr.
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
demo.launch()
|
|
|
|
| 264 |
generated_text += token_str
|
| 265 |
yield generated_text
|
| 266 |
|
|
|
|
|
|
|
|
|
|
| 267 |
# ============================================================================
|
| 268 |
+
# 3. GRADIO INTERFACE (Using Blocks for robustness)
|
| 269 |
# ============================================================================
|
| 270 |
|
| 271 |
# Initialize engine globally
|
|
|
|
| 285 |
):
|
| 286 |
yield current_text
|
| 287 |
|
| 288 |
+
# Custom CSS
|
| 289 |
custom_css = """
|
| 290 |
+
#container {max_width: 800px; margin: auto;}
|
| 291 |
+
.output-text {min_height: 300px;}
|
| 292 |
"""
|
| 293 |
|
| 294 |
+
with gr.Blocks(css=custom_css) as demo:
|
| 295 |
+
with gr.Column(elem_id="container"):
|
| 296 |
+
gr.Markdown("# i3-200m-v2 (RWKV-Hybrid)")
|
| 297 |
+
gr.Markdown("A 200M parameter hybrid model combining RWKV (RNN) and Standard Attention layers.")
|
| 298 |
+
|
| 299 |
+
with gr.Group():
|
| 300 |
+
prompt_input = gr.Textbox(
|
| 301 |
+
lines=3,
|
| 302 |
+
placeholder="Enter your prompt here...",
|
| 303 |
+
label="Input Prompt"
|
| 304 |
+
)
|
| 305 |
+
with gr.Row():
|
| 306 |
+
max_tokens = gr.Slider(minimum=10, maximum=512, value=150, step=10, label="Max New Tokens")
|
| 307 |
+
temp = gr.Slider(minimum=0.1, maximum=2.0, value=0.8, step=0.1, label="Temperature")
|
| 308 |
+
topk = gr.Slider(minimum=1, maximum=100, value=40, step=1, label="Top-K")
|
| 309 |
+
|
| 310 |
+
submit_btn = gr.Button("Generate", variant="primary")
|
| 311 |
+
|
| 312 |
+
output_text = gr.Textbox(
|
| 313 |
+
lines=10,
|
| 314 |
+
label="Generated Output",
|
| 315 |
+
elem_classes="output-text"
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
# Set up event listeners
|
| 319 |
+
submit_btn.click(
|
| 320 |
+
fn=predict,
|
| 321 |
+
inputs=[prompt_input, max_tokens, temp, topk],
|
| 322 |
+
outputs=output_text
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
# Example inputs to easily test
|
| 326 |
+
gr.Examples(
|
| 327 |
+
examples=[
|
| 328 |
+
["The history of science is"],
|
| 329 |
+
["Once upon a time in a digital world,"],
|
| 330 |
+
["The quick brown fox jumps over"]
|
| 331 |
+
],
|
| 332 |
+
inputs=prompt_input
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
if __name__ == "__main__":
|
| 336 |
+
demo.queue()
|
| 337 |
demo.launch()
|