Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
model_name = "OpenAssistant/replit-1B"
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 10 |
|
| 11 |
-
# Créer le pipeline pour la génération
|
| 12 |
chatbot = pipeline(
|
| 13 |
"text-generation",
|
| 14 |
model=model,
|
| 15 |
tokenizer=tokenizer,
|
| 16 |
-
|
| 17 |
)
|
| 18 |
|
| 19 |
-
# Prompt système pour Aria
|
| 20 |
system_prompt = "Tu es Aria, une IA bienveillante et polie qui répond de façon concise et claire."
|
| 21 |
|
| 22 |
-
# Fonction de chat
|
| 23 |
def chat(message, history=[]):
|
| 24 |
context = "\n".join([f"Utilisateur: {m[0]}\nAria: {m[1]}" for m in history])
|
| 25 |
prompt = f"{system_prompt}\n{context}\nUtilisateur: {message}\nAria:"
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
reply = reply.split("Aria:")[-1].strip()
|
| 31 |
-
|
| 32 |
history.append((message, reply))
|
| 33 |
return reply, history
|
| 34 |
|
| 35 |
-
# Interface Gradio
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
chat_ui = gr.Chatbot()
|
| 38 |
msg = gr.Textbox(placeholder="Écris un message...")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 3 |
|
| 4 |
+
MODEL = "prithivMLmods/Llama-SmolTalk-3.2-1B-Instruct"
|
|
|
|
| 5 |
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL, device_map="auto")
|
|
|
|
| 8 |
|
|
|
|
| 9 |
chatbot = pipeline(
|
| 10 |
"text-generation",
|
| 11 |
model=model,
|
| 12 |
tokenizer=tokenizer,
|
| 13 |
+
device_map="auto",
|
| 14 |
)
|
| 15 |
|
|
|
|
| 16 |
system_prompt = "Tu es Aria, une IA bienveillante et polie qui répond de façon concise et claire."
|
| 17 |
|
|
|
|
| 18 |
def chat(message, history=[]):
|
| 19 |
context = "\n".join([f"Utilisateur: {m[0]}\nAria: {m[1]}" for m in history])
|
| 20 |
prompt = f"{system_prompt}\n{context}\nUtilisateur: {message}\nAria:"
|
| 21 |
+
|
| 22 |
+
resp = chatbot(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)[0]["generated_text"]
|
| 23 |
+
reply = resp.split("Aria:")[-1].strip()
|
| 24 |
+
|
|
|
|
|
|
|
| 25 |
history.append((message, reply))
|
| 26 |
return reply, history
|
| 27 |
|
|
|
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
chat_ui = gr.Chatbot()
|
| 30 |
msg = gr.Textbox(placeholder="Écris un message...")
|