Fix app
Browse files
app.py
CHANGED
@@ -1,7 +1,40 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, pipeline
|
3 |
|
4 |
+
def initialize_model():
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("Nac31/Sacha-Mistral-0", trust_remote_code=True)
|
6 |
+
pipe = pipeline(
|
7 |
+
"text-generation",
|
8 |
+
model="Nac31/Sacha-Mistral-0",
|
9 |
+
tokenizer=tokenizer,
|
10 |
+
trust_remote_code=True
|
11 |
+
)
|
12 |
+
return pipe
|
13 |
|
14 |
+
def generate_response(message, temperature=0.7, max_length=500):
|
15 |
+
try:
|
16 |
+
pipe = initialize_model()
|
17 |
+
response = pipe(
|
18 |
+
message,
|
19 |
+
max_length=max_length,
|
20 |
+
temperature=temperature,
|
21 |
+
do_sample=True
|
22 |
+
)[0]['generated_text']
|
23 |
+
return response
|
24 |
+
except Exception as e:
|
25 |
+
return f"Une erreur s'est produite : {str(e)}"
|
26 |
+
|
27 |
+
# Interface Gradio
|
28 |
+
demo = gr.Interface(
|
29 |
+
fn=generate_response,
|
30 |
+
inputs=[
|
31 |
+
gr.Textbox(label="Votre message", placeholder="Entrez votre message ici..."),
|
32 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Température")
|
33 |
+
],
|
34 |
+
outputs=gr.Textbox(label="Réponse"),
|
35 |
+
title="Chat avec Sacha-Mistral",
|
36 |
+
description="Un assistant conversationnel en français basé sur le modèle Sacha-Mistral"
|
37 |
+
)
|
38 |
+
|
39 |
+
if __name__ == "__main__":
|
40 |
+
demo.launch()
|