El-Alberto67 commited on
Commit
5d5cf50
·
verified ·
1 Parent(s): 365b8dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -23
app.py CHANGED
@@ -19,42 +19,33 @@ chatbot = pipeline(
19
  device_map="auto"
20
  )
21
 
22
- system_prompt = """Tu es Aria, une IA bienveillante, claire et polie.
23
- Réponds directement aux questions en une ou plusieurs phrases complètes.
24
- Ne répète jamais le message de l'utilisateur. Ne joue pas un rôle.
25
- N'inclus pas "Utilisateur:" ou "Aria:" dans ta réponse."""
26
 
27
  def clean_reply(text):
28
- # Supprimer tout ce qui pourrait être un rôle ou répétition
29
- text = re.sub(r"^.*?Aria:\s*", "", text, flags=re.DOTALL)
30
- text = re.sub(r"Utilisateur:.*", "", text, flags=re.DOTALL)
31
- text = text.strip()
32
- return text
33
 
34
- def chat(message, history=[]):
35
- history = history[-3:]
36
-
37
- # Contexte plus naturel
38
- context = "\n".join([f"{m[0]}\nRéponse: {m[1]}" for m in history])
39
- prompt = f"{system_prompt}\n\n{context}\n{message}\nRéponse:"
40
 
41
  resp = chatbot(
42
  prompt,
43
- max_new_tokens=120,
44
  do_sample=True,
45
  temperature=0.7,
46
- top_p=0.9,
47
- repetition_penalty=1.1
48
  )[0]["generated_text"]
49
 
50
  reply = clean_reply(resp)
51
- history.append([message, reply])
52
-
53
- return history, history
54
 
55
  with gr.Blocks() as demo:
56
- chat_ui = gr.Chatbot()
57
  msg = gr.Textbox(placeholder="Écris un message...")
58
- msg.submit(chat, [msg, chat_ui], [chat_ui, chat_ui])
 
59
 
60
  demo.launch()
 
19
  device_map="auto"
20
  )
21
 
22
+ system_prompt = """Tu es Aria, une IA gentille et claire.
23
+ Réponds directement à la question de l'utilisateur en français,
24
+ en une ou deux phrases complètes.
25
+ Ne répète pas la question. Ne joue pas de rôle."""
26
 
27
  def clean_reply(text):
28
+ # Retirer tout texte avant ou après la vraie réponse
29
+ text = re.sub(r"^.*?:", "", text, flags=re.DOTALL) # supprime jusqu'au premier ":"
30
+ return text.strip()
 
 
31
 
32
+ def chat(message):
33
+ prompt = f"{system_prompt}\n\nQuestion : {message}\nRéponse :"
 
 
 
 
34
 
35
  resp = chatbot(
36
  prompt,
37
+ max_new_tokens=80,
38
  do_sample=True,
39
  temperature=0.7,
40
+ top_p=0.9
 
41
  )[0]["generated_text"]
42
 
43
  reply = clean_reply(resp)
44
+ return reply
 
 
45
 
46
  with gr.Blocks() as demo:
 
47
  msg = gr.Textbox(placeholder="Écris un message...")
48
+ output = gr.Textbox(label="Réponse d'Aria")
49
+ msg.submit(lambda m: chat(m), msg, output)
50
 
51
  demo.launch()