Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +24 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
model_name = "microsoft/DialoGPT-medium"
|
| 5 |
+
|
| 6 |
+
def converse(message, chat_history):
|
| 7 |
+
if chat_history is None:
|
| 8 |
+
chat_history = []
|
| 9 |
+
conversational_pipeline = pipeline('conversational', model=model_name, use_auth_token=None)
|
| 10 |
+
from transformers import Conversation
|
| 11 |
+
convo = Conversation(message)
|
| 12 |
+
result = conversational_pipeline(convo)
|
| 13 |
+
return result.generated_responses[-1], chat_history + [[message, result.generated_responses[-1]]]
|
| 14 |
+
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("# Dialogue Bot")
|
| 17 |
+
gr.Markdown("Powered by microsoft/DialoGPT-medium")
|
| 18 |
+
chatbot = gr.Chatbot()
|
| 19 |
+
msg = gr.Textbox(label="Message", placeholder="Type your message...")
|
| 20 |
+
btn = gr.Button("Send")
|
| 21 |
+
btn.click(fn=converse, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|