Update app.file
Browse files
app.py
CHANGED
@@ -3,7 +3,37 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
3 |
import torch
|
4 |
|
5 |
# Chargement du modèle Mistral
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
9 |
|
|
|
3 |
import torch
|
4 |
|
5 |
# Chargement du modèle Mistral
|
6 |
+
import streamlit as st
|
7 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
8 |
+
import torch
|
9 |
+
|
10 |
+
# Chargement du modèle Mistral
|
11 |
+
model_name = "mistralai/Ministral-8B-Instruct-2410"
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
14 |
+
|
15 |
+
# Fonction pour générer des réponses
|
16 |
+
def generate_response(prompt):
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
18 |
+
outputs = model.generate(inputs['input_ids'], max_length=150)
|
19 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
return response
|
21 |
+
|
22 |
+
# Configuration de l'application Streamlit
|
23 |
+
st.title("Chatbot Mistral")
|
24 |
+
st.write("Posez une question au chatbot :")
|
25 |
+
|
26 |
+
# Zone de texte pour l'entrée utilisateur
|
27 |
+
user_input = st.text_input("Vous :")
|
28 |
+
|
29 |
+
if st.button("Envoyer"):
|
30 |
+
if user_input:
|
31 |
+
with st.spinner("Génération de la réponse..."):
|
32 |
+
response = generate_response(user_input)
|
33 |
+
st.write("Chatbot :", response)
|
34 |
+
else:
|
35 |
+
st.write("Veuillez entrer un message.")
|
36 |
+
|
37 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
38 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
39 |
|