FlameF0X commited on
Commit
d1fc617
·
verified ·
1 Parent(s): 61f5f67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -26
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 for a cleaner look
292
  custom_css = """
293
- #component-0 {max_width: 800px; margin: auto;}
 
294
  """
295
 
296
- with gr.Interface(
297
- fn=predict,
298
- inputs=[
299
- gr.Textbox(lines=3, placeholder="Enter your prompt here...", label="Input Prompt"),
300
- gr.Slider(minimum=10, maximum=512, value=150, step=10, label="Max New Tokens"),
301
- gr.Slider(minimum=0.1, maximum=2.0, value=0.8, step=0.1, label="Temperature"),
302
- gr.Slider(minimum=1, maximum=100, value=40, step=1, label="Top-K"),
303
- ],
304
- outputs=gr.Textbox(lines=10, label="Generated Output"),
305
- title="i3-200m-v2 (RWKV-Hybrid)",
306
- description="A 200M parameter hybrid model combining RWKV (RNN) and Standard Attention layers.",
307
- css=custom_css,
308
- examples=[
309
- ["The history of science is"],
310
- ["Once upon a time in a digital world,"],
311
- ["The quick brown fox jumps over"]
312
- ],
313
- cache_examples=False
314
- ) as demo:
315
- demo.queue() # Enable queuing for streaming
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()