Spaces:
Runtime error
Runtime error
Abid
commited on
Commit
·
927fc17
0
Parent(s):
first try
Browse files- README.md +11 -0
- app.py +50 -0
- img/img1.png +0 -0
- requirements.txt +2 -0
README.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Rick & Morty Block Party
|
3 |
+
emoji: 💃
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
---
|
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
+
import torch
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
5 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
6 |
+
|
7 |
+
|
8 |
+
def predict(input, history=[]):
|
9 |
+
# tokenize the new input sentence
|
10 |
+
new_user_input_ids = tokenizer.encode(
|
11 |
+
input + tokenizer.eos_token, return_tensors="pt"
|
12 |
+
)
|
13 |
+
|
14 |
+
# append the new user input tokens to the chat history
|
15 |
+
bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
16 |
+
|
17 |
+
# generate a response
|
18 |
+
history = model.generate(
|
19 |
+
bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id
|
20 |
+
).tolist()
|
21 |
+
|
22 |
+
# convert the tokens to text, and then split the responses into the right format
|
23 |
+
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
24 |
+
response = [
|
25 |
+
(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)
|
26 |
+
] # convert to tuples of list
|
27 |
+
return response, history
|
28 |
+
|
29 |
+
|
30 |
+
import gradio as gr
|
31 |
+
|
32 |
+
demo = gr.Blocks()
|
33 |
+
|
34 |
+
with demo:
|
35 |
+
gr.Markdown(
|
36 |
+
"""
|
37 |
+

|
38 |
+
# Let's start the party with Rick & Morty
|
39 |
+
Chat with Morty by typing in the input box below.
|
40 |
+
""")
|
41 |
+
|
42 |
+
gr.Interface(
|
43 |
+
fn=predict,
|
44 |
+
theme="default",
|
45 |
+
css=".footer {display:none !important}",
|
46 |
+
inputs=["text", "state"],
|
47 |
+
outputs=["chatbot", "state"],
|
48 |
+
)
|
49 |
+
|
50 |
+
demo.launch()
|
img/img1.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|