Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import time
|
2 |
+
from transformers import pipeline, Conversation, AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
model_name = "microsoft/DialoGPT-large"
|
6 |
+
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, padding_side='left')
|
9 |
+
|
10 |
+
chatbot = pipeline(task="conversational", model = model, tokenizer = tokenizer)
|
11 |
+
|
12 |
+
past_user_inputs = []
|
13 |
+
generated_responses = []
|
14 |
+
|
15 |
+
def chocolate_ai(message, history):
|
16 |
+
conversation = Conversation(message, past_user_inputs = past_user_inputs, generated_responses = generated_responses)
|
17 |
+
conversation = chatbot(conversation)
|
18 |
+
|
19 |
+
past_user_inputs.append(message)
|
20 |
+
generated_responses.append(conversation.generated_responses[-1])
|
21 |
+
|
22 |
+
return conversation.generated_responses[-1]
|
23 |
+
|
24 |
+
gradio_interface = gr.ChatInterface(chocolate_ai, title="Chocolate AI", description="Type to start a conversation.")
|
25 |
+
gradio_interface.launch()
|