Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,42 +19,33 @@ chatbot = pipeline(
|
|
19 |
device_map="auto"
|
20 |
)
|
21 |
|
22 |
-
system_prompt = """Tu es Aria, une IA
|
23 |
-
Réponds directement
|
24 |
-
|
25 |
-
|
26 |
|
27 |
def clean_reply(text):
|
28 |
-
#
|
29 |
-
text = re.sub(r"
|
30 |
-
text
|
31 |
-
text = text.strip()
|
32 |
-
return text
|
33 |
|
34 |
-
def chat(message
|
35 |
-
|
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=
|
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 |
-
|
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 |
-
|
|
|
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()
|