FlameF0X commited on
Commit
e2ba941
Β·
verified Β·
1 Parent(s): d1fc617

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +118 -37
app.py CHANGED
@@ -265,7 +265,7 @@ class SpaceInferenceEngine:
265
  yield generated_text
266
 
267
  # ============================================================================
268
- # 3. GRADIO INTERFACE (Using Blocks for robustness)
269
  # ============================================================================
270
 
271
  # Initialize engine globally
@@ -273,8 +273,9 @@ print("Starting Engine...")
273
  engine = SpaceInferenceEngine()
274
 
275
  def predict(prompt, max_tokens, temperature, top_k):
276
- if not prompt:
277
- return "Please enter a prompt."
 
278
 
279
  # Use the generator for streaming
280
  for current_text in engine.generate_stream(
@@ -287,50 +288,130 @@ def predict(prompt, max_tokens, temperature, top_k):
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()
 
265
  yield generated_text
266
 
267
  # ============================================================================
268
+ # 3. GRADIO INTERFACE (UI Upgrade)
269
  # ============================================================================
270
 
271
  # Initialize engine globally
 
273
  engine = SpaceInferenceEngine()
274
 
275
  def predict(prompt, max_tokens, temperature, top_k):
276
+ if not prompt.strip():
277
+ yield "⚠️ Please enter a prompt to generate text."
278
+ return
279
 
280
  # Use the generator for streaming
281
  for current_text in engine.generate_stream(
 
288
 
289
  # Custom CSS
290
  custom_css = """
291
+ .gradio-container {
292
+ max-width: 1200px !important;
293
+ }
294
+ .main-header {
295
+ text-align: center;
296
+ margin-bottom: 2rem;
297
+ }
298
  """
299
 
300
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
301
+ # Header
302
+ with gr.Row():
303
+ gr.Markdown(
304
+ """
305
+ # πŸš€ i3-200M Text Generation
306
+ ### Powered by RWKV-Hybrid Architecture
307
+ Generate creative text using the i3-200M language model combining RNN efficiency with Attention precision.
308
+ """,
309
+ elem_classes="main-header"
310
+ )
311
+
312
+ # Main Generation Area
313
+ with gr.Row():
314
+ # Left Column: Inputs
315
+ with gr.Column(scale=2):
316
  prompt_input = gr.Textbox(
317
+ label="✍️ Enter Your Prompt",
318
+ placeholder="Once upon a time in a distant galaxy...",
319
+ lines=4,
320
+ max_lines=8
321
  )
 
 
 
 
322
 
323
+ with gr.Accordion("βš™οΈ Generation Parameters", open=True):
324
+ with gr.Row():
325
+ max_tokens_input = gr.Slider(
326
+ minimum=10,
327
+ maximum=512,
328
+ value=150,
329
+ step=10,
330
+ label="Max Tokens",
331
+ info="Maximum number of tokens to generate"
332
+ )
333
+ temp_input = gr.Slider(
334
+ minimum=0.1,
335
+ maximum=2.0,
336
+ value=0.8,
337
+ step=0.1,
338
+ label="Temperature",
339
+ info="Higher = more creative, Lower = more focused"
340
+ )
341
+
342
+ topk_input = gr.Slider(
343
+ minimum=1,
344
+ maximum=100,
345
+ value=40,
346
+ step=1,
347
+ label="Top-k Sampling",
348
+ info="Number of top tokens to consider"
349
+ )
350
+
351
+ with gr.Row():
352
+ generate_btn = gr.Button("🎨 Generate Text", variant="primary", size="lg")
353
+ clear_btn = gr.ClearButton(components=[prompt_input], value="πŸ—‘οΈ Clear", size="lg")
354
 
355
+ # Right Column: Output
356
+ with gr.Column(scale=2):
357
+ output_text = gr.Textbox(
358
+ label="πŸ“ Generated Output",
359
+ lines=12,
360
+ max_lines=20,
361
+ show_copy_button=True
362
+ )
363
+
364
+ # Examples Section
365
+ with gr.Row():
366
  gr.Examples(
367
  examples=[
368
+ ["The history of science is", 150, 0.7, 50],
369
+ ["In a world where technology and nature coexist", 200, 0.9, 40],
370
+ ["The scientist discovered something remarkable", 120, 0.8, 45],
371
  ],
372
+ inputs=[prompt_input, max_tokens_input, temp_input, topk_input],
373
+ label="πŸ’‘ Try These Examples"
374
  )
375
+
376
+ # Developer Panel
377
+ with gr.Accordion("πŸ”§ Developer Info", open=False):
378
+ total_params = sum(p.numel() for p in engine.model.parameters())
379
+
380
+ with gr.Row():
381
+ with gr.Column():
382
+ gr.Markdown(f"""
383
+ **Model Architecture:**
384
+ - **Model:** i3-200M Hybrid
385
+ - **Device:** {engine.device}
386
+ - **Vocab Size:** {engine.config['vocab_size']:,}
387
+ - **Parameters:** {total_params:,} ({total_params/1e6:.2f}M)
388
+ """)
389
+
390
+ with gr.Column():
391
+ gr.Markdown(f"""
392
+ **Configuration:**
393
+ - **d_model:** {engine.config['d_model']}
394
+ - **RWKV Layers:** {engine.config['rwkv_layers']}
395
+ - **Attention Layers:** {engine.config['attn_layers']}
396
+ - **Max Seq Len:** {engine.model.max_seq_len}
397
+ """)
398
+
399
+ # Footer
400
+ gr.Markdown(
401
+ """
402
+ ---
403
+ <div style="text-align: center; color: #666;">
404
+ <p>Built with ❀️ using Gradio | Model: FlameF0X/i3-200m-v2</p>
405
+ </div>
406
+ """
407
+ )
408
+
409
+ # Connect UI
410
+ generate_btn.click(
411
+ predict,
412
+ inputs=[prompt_input, max_tokens_input, temp_input, topk_input],
413
+ outputs=[output_text]
414
+ )
415
 
416
  if __name__ == "__main__":
417
  demo.queue()