Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
|
|
3 |
|
4 |
MODEL = "prithivMLmods/Llama-SmolTalk-3.2-1B-Instruct"
|
5 |
|
@@ -18,37 +19,37 @@ chatbot = pipeline(
|
|
18 |
device_map="auto"
|
19 |
)
|
20 |
|
21 |
-
system_prompt = """Tu es Aria, une IA
|
22 |
-
Réponds
|
23 |
-
Ne
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def chat(message, history=[]):
|
28 |
-
history = history[-3:]
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
32 |
|
33 |
resp = chatbot(
|
34 |
prompt,
|
35 |
-
max_new_tokens=120,
|
36 |
do_sample=True,
|
37 |
temperature=0.7,
|
38 |
top_p=0.9,
|
39 |
repetition_penalty=1.1
|
40 |
)[0]["generated_text"]
|
41 |
|
42 |
-
|
43 |
-
reply = resp.split("Aria:")[-1].strip()
|
44 |
-
|
45 |
-
# Supprime si "Utilisateur:" est revenu dans la génération
|
46 |
-
if "Utilisateur:" in reply:
|
47 |
-
reply = reply.split("Utilisateur:")[0].strip()
|
48 |
-
|
49 |
history.append([message, reply])
|
50 |
|
51 |
-
# Retourner au format Gradio Chatbot
|
52 |
return history, history
|
53 |
|
54 |
with gr.Blocks() as demo:
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
+
import re
|
4 |
|
5 |
MODEL = "prithivMLmods/Llama-SmolTalk-3.2-1B-Instruct"
|
6 |
|
|
|
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:
|