Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use a pipeline as a high-level helper
|
2 |
+
from transformers import pipeline, Conversation
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
+
chatbot = pipeline("conversational", model="ericzhou/DialoGPT-Medium-Rick_v2")
|
7 |
+
conversation = None # initialization
|
8 |
+
def predict(sentence,history) :
|
9 |
+
global conversation
|
10 |
+
if not conversation :
|
11 |
+
# initial generation
|
12 |
+
conversation = Conversation(sentence)
|
13 |
+
else :
|
14 |
+
# mid conversation
|
15 |
+
conversation.add_user_input(sentence)
|
16 |
+
conversation = chatbot(conversation)
|
17 |
+
return conversation.generated_responses[-1]
|
18 |
+
|
19 |
+
gr.ChatInterface(predict).queue().launch()
|