sylvielsstfr
commited on
Commit
·
71474a5
1
Parent(s):
c529a92
update
Browse files
app.py
CHANGED
|
@@ -1,27 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# GPT-2
|
| 5 |
generator = pipeline("text-generation", model="gpt2")
|
| 6 |
|
| 7 |
def respond(message, history):
|
|
|
|
| 8 |
history = history or []
|
| 9 |
|
| 10 |
-
# Générer
|
| 11 |
answer = generator(message, max_length=50, do_sample=True)[0]["generated_text"]
|
| 12 |
|
| 13 |
-
# Ajouter
|
| 14 |
history.append([message, answer])
|
| 15 |
|
| 16 |
-
# Retourner
|
| 17 |
-
return history
|
| 18 |
|
| 19 |
-
#
|
| 20 |
iface = gr.ChatInterface(respond, title="Chat Demo")
|
| 21 |
-
iface.launch()
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Modèle public GPT-2 pour réponses réalistes
|
| 5 |
generator = pipeline("text-generation", model="gpt2")
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
+
# Initialisation de l'historique
|
| 9 |
history = history or []
|
| 10 |
|
| 11 |
+
# Générer une réponse
|
| 12 |
answer = generator(message, max_length=50, do_sample=True)[0]["generated_text"]
|
| 13 |
|
| 14 |
+
# Ajouter la conversation sous forme de liste [user, bot]
|
| 15 |
history.append([message, answer])
|
| 16 |
|
| 17 |
+
# Retourner textbox vide + historique pour Gradio 3.43
|
| 18 |
+
return "", history
|
| 19 |
|
| 20 |
+
# Créer l'interface Chat
|
| 21 |
iface = gr.ChatInterface(respond, title="Chat Demo")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Lancer localement
|
| 24 |
+
iface.launch()
|
| 25 |
|
| 26 |
|