Spaces:
Sleeping
Sleeping
DJONG-WANG
commited on
Commit
•
7861198
1
Parent(s):
85a0456
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import random
|
4 |
+
import time
|
5 |
+
|
6 |
+
# Création du pipeline pour le modèle de Hugging Face
|
7 |
+
pipe = pipeline(task='text-generation', model='meta-llama/Llama-2-7b-chat-hf')
|
8 |
+
|
9 |
+
# Création de l'interface Gradio
|
10 |
+
with gr.Blocks() as demo:
|
11 |
+
chatbot = gr.Chatbot()
|
12 |
+
msg = gr.Textbox()
|
13 |
+
clear = gr.ClearButton([msg, chatbot])
|
14 |
+
|
15 |
+
def respond(message, chat_history):
|
16 |
+
# Utilisation du modèle de Hugging Face pour générer une réponse
|
17 |
+
bot_message = pipe(message, max_length=50)[0]['generated_text']
|
18 |
+
chat_history.append((message, bot_message))
|
19 |
+
time.sleep(2)
|
20 |
+
return "", chat_history
|
21 |
+
|
22 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
demo.launch()
|