Gems234 commited on
Commit
522870a
·
verified ·
1 Parent(s): 13dd02d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -15
app.py CHANGED
@@ -57,7 +57,7 @@ print(f"✅ Modèle chargé! Threads: {n_threads}")
57
  lock = threading.Lock()
58
  conversations = {"Conversation 1": []}
59
  stop_generation = threading.Event()
60
- system_prompt_used = False # Pour suivre si le system prompt a été utilisé
61
 
62
  # -------------------------
63
  # FONCTIONS UTILITAIRES OPTIMISÉES
@@ -113,9 +113,10 @@ def send_message_stream(user_message, displayed_history, current_chat_name):
113
 
114
  formatted_prompt = build_conversation_prompt(local_hist[:-1], str(user_message))
115
  partial = ""
 
116
 
117
  try:
118
- # Utilisation directe du streaming sans buffering complexe
119
  stream = llm.create_completion(
120
  prompt=formatted_prompt,
121
  stream=True,
@@ -134,7 +135,9 @@ def send_message_stream(user_message, displayed_history, current_chat_name):
134
  token = chunk["choices"][0].get("text", "")
135
  if token:
136
  partial += token
137
- # Mise à jour immédiate pour une meilleure réactivité
 
 
138
  cleaned = clean_output(partial)
139
  local_hist[-1] = (str(user_message), cleaned)
140
  yield local_hist, ""
@@ -146,7 +149,7 @@ def send_message_stream(user_message, displayed_history, current_chat_name):
146
 
147
  finally:
148
  end_time = time.time()
149
- print(f"⏱️ Génération: {end_time - start_time:.2f}s - {len(partial)} chars")
150
  with lock:
151
  conversations[current_chat_name] = local_hist.copy()
152
  yield local_hist, ""
@@ -178,7 +181,7 @@ def clear_chat():
178
  global system_prompt_used
179
  with lock:
180
  conversations["Conversation 1"] = []
181
- system_prompt_used = False # Réinitialiser pour le prochain chat
182
  return [], "Conversation 1"
183
 
184
  # -------------------------
@@ -363,17 +366,30 @@ css = """
363
  background: #1e293b;
364
  border-radius: 8px;
365
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  """
367
 
368
- with gr.Blocks(css=css, title="Alisia Chat - Ultra Rapide", theme=gr.themes.Soft()) as demo:
369
  history_visible = gr.State(True)
370
  current_chat = gr.State("Conversation 1")
371
 
372
  with gr.Row(elem_id="topbar"):
373
  menu_btn = gr.Button("☰", elem_classes="hamburger")
374
- gr.Markdown("### 💬 Alisia <span class='alisia-badge'>AI Assistant</span>", elem_id="title")
375
  gr.HTML("<div style='flex:1'></div>")
376
- gr.Markdown(f"<small style='color:#94a3b8'>CPU: {n_threads} threads • Mode Rapide</small>")
377
 
378
  with gr.Row():
379
  with gr.Column(scale=1, visible=True, elem_id="leftcol") as left_column:
@@ -397,10 +413,11 @@ with gr.Blocks(css=css, title="Alisia Chat - Ultra Rapide", theme=gr.themes.Soft
397
 
398
  gr.Markdown("""
399
  <div class="perf-info">
400
- <strong>🚀 Mode Alpaca Optimisé</strong><br>
401
- System prompt unique<br>
402
- Streaming direct<br>
403
- • Format Alpaca pur
 
404
  </div>
405
  """)
406
 
@@ -500,9 +517,10 @@ with gr.Blocks(css=css, title="Alisia Chat - Ultra Rapide", theme=gr.themes.Soft
500
  # LANCEMENT
501
  # -------------------------
502
  if __name__ == "__main__":
503
- print("🚀 Lancement de l'interface optimisée...")
504
- print("📋 Format Alpaca avec system prompt unique")
505
- print(f" Threads CPU: {n_threads}")
 
506
 
507
  demo.launch(
508
  share=True,
 
57
  lock = threading.Lock()
58
  conversations = {"Conversation 1": []}
59
  stop_generation = threading.Event()
60
+ system_prompt_used = False
61
 
62
  # -------------------------
63
  # FONCTIONS UTILITAIRES OPTIMISÉES
 
113
 
114
  formatted_prompt = build_conversation_prompt(local_hist[:-1], str(user_message))
115
  partial = ""
116
+ token_count = 0
117
 
118
  try:
119
+ # STREAMING RÉEL - Token par token
120
  stream = llm.create_completion(
121
  prompt=formatted_prompt,
122
  stream=True,
 
135
  token = chunk["choices"][0].get("text", "")
136
  if token:
137
  partial += token
138
+ token_count += 1
139
+
140
+ # MISE À JOUR IMMÉDIATE - VRAI STREAMING
141
  cleaned = clean_output(partial)
142
  local_hist[-1] = (str(user_message), cleaned)
143
  yield local_hist, ""
 
149
 
150
  finally:
151
  end_time = time.time()
152
+ print(f"⏱️ Génération: {end_time - start_time:.2f}s - {token_count} tokens")
153
  with lock:
154
  conversations[current_chat_name] = local_hist.copy()
155
  yield local_hist, ""
 
181
  global system_prompt_used
182
  with lock:
183
  conversations["Conversation 1"] = []
184
+ system_prompt_used = False
185
  return [], "Conversation 1"
186
 
187
  # -------------------------
 
366
  background: #1e293b;
367
  border-radius: 8px;
368
  }
369
+
370
+ .streaming-indicator {
371
+ color: #10b981;
372
+ font-size: 12px;
373
+ margin-left: 10px;
374
+ animation: pulse 1.5s infinite;
375
+ }
376
+
377
+ @keyframes pulse {
378
+ 0% { opacity: 1; }
379
+ 50% { opacity: 0.5; }
380
+ 100% { opacity: 1; }
381
+ }
382
  """
383
 
384
+ with gr.Blocks(css=css, title="Alisia Chat - Streaming Réel", theme=gr.themes.Soft()) as demo:
385
  history_visible = gr.State(True)
386
  current_chat = gr.State("Conversation 1")
387
 
388
  with gr.Row(elem_id="topbar"):
389
  menu_btn = gr.Button("☰", elem_classes="hamburger")
390
+ gr.Markdown("### 💬 Alisia <span class='alisia-badge'>Real Streaming</span><span class='streaming-indicator'>● LIVE</span>", elem_id="title")
391
  gr.HTML("<div style='flex:1'></div>")
392
+ gr.Markdown(f"<small style='color:#94a3b8'>Token-par-token {n_threads} threads</small>")
393
 
394
  with gr.Row():
395
  with gr.Column(scale=1, visible=True, elem_id="leftcol") as left_column:
 
413
 
414
  gr.Markdown("""
415
  <div class="perf-info">
416
+ <strong>🚀 STREAMING RÉEL</strong><br>
417
+ Token-par-token<br>
418
+ Latence minimale<br>
419
+ • Format Alpaca pur<br>
420
+ • System prompt unique
421
  </div>
422
  """)
423
 
 
517
  # LANCEMENT
518
  # -------------------------
519
  if __name__ == "__main__":
520
+ print("🚀 Lancement avec STREAMING RÉEL...")
521
+ print(" Token-par-token - Latence minimale")
522
+ print(f"💻 Threads CPU: {n_threads}")
523
+ print("📊 Monitoring temps réel activé")
524
 
525
  demo.launch(
526
  share=True,