Spaces:
Runtime error
Runtime error
armandstrickernlp
commited on
Commit
·
c039d26
1
Parent(s):
cd30edd
create app
Browse files
app.py
CHANGED
|
@@ -16,58 +16,16 @@ def generate_response(prompt):
|
|
| 16 |
#<|context|> <|user|> I want to go to the restaurant.<|endofcontext|>
|
| 17 |
|
| 18 |
|
| 19 |
-
def chat(message, history):
|
| 20 |
-
history = history or []
|
| 21 |
-
if history == []:
|
| 22 |
-
context = '<|context|> <|user|> ' + message + ' <|endofcontext|> '
|
| 23 |
-
else:
|
| 24 |
-
context, _ = history[-1][0].split('<|endofcontext|>')
|
| 25 |
-
context += ' <|system|> '
|
| 26 |
-
context += history[-1][1].split('<|response|>')[1]
|
| 27 |
-
context = context.replace('<|endofresponse|>', '')
|
| 28 |
-
context += ' <|user|> ' + message + ' <|endofcontext|> '
|
| 29 |
|
| 30 |
-
output = generate_response(context)
|
| 31 |
-
_ , response = output.split('<|endofcontext|>')
|
| 32 |
|
| 33 |
-
history.append((message, response))
|
| 34 |
-
|
| 35 |
-
return history, history
|
| 36 |
-
|
| 37 |
-
import random
|
| 38 |
-
def chat_test(message, history):
|
| 39 |
-
history = history or []
|
| 40 |
-
if message.startswith("How many"):
|
| 41 |
-
response = random.randint(1, 10)
|
| 42 |
-
elif message.startswith("How"):
|
| 43 |
-
response = random.choice(["Great", "Good", "Okay", "Bad"])
|
| 44 |
-
elif message.startswith("Where"):
|
| 45 |
-
response = random.choice(["Here", "There", "Somewhere"])
|
| 46 |
-
else:
|
| 47 |
-
response = "I don't know"
|
| 48 |
-
history.append((message, response))
|
| 49 |
-
return history, history
|
| 50 |
-
|
| 51 |
-
import gradio as gr
|
| 52 |
-
|
| 53 |
-
chatbot = gr.Chatbot(color_map=("green", "gray"))
|
| 54 |
-
|
| 55 |
-
iface = gr.Interface(chat_test,
|
| 56 |
-
["text", "state"],
|
| 57 |
-
[chatbot, "state"],
|
| 58 |
-
allow_screenshot=False,
|
| 59 |
-
allow_flagging="never",
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
"""
|
| 65 |
iface = gr.Interface(fn=generate_response,
|
| 66 |
inputs="text",
|
| 67 |
outputs="text",
|
| 68 |
title="gpt2-TOD",
|
| 69 |
-
examples=[["<|context|> <|user|> I'm super hungry ! I want to go to the restaurant.<|endofcontext|>"]
|
|
|
|
|
|
|
| 70 |
description="Passing in a task-oriented dialogue context generates a belief state, actions to take and a response based on those actions",
|
| 71 |
)
|
| 72 |
-
|
| 73 |
-
iface.launch(
|
|
|
|
| 16 |
#<|context|> <|user|> I want to go to the restaurant.<|endofcontext|>
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
iface = gr.Interface(fn=generate_response,
|
| 22 |
inputs="text",
|
| 23 |
outputs="text",
|
| 24 |
title="gpt2-TOD",
|
| 25 |
+
examples=[["<|context|> <|user|> I'm super hungry ! I want to go to the restaurant.<|endofcontext|>"],
|
| 26 |
+
"<|context|> <|user|> I want to go to the restaurant.\
|
| 27 |
+
<|system|> What food would you like to eat ? <|user|> Italian sounds good. <|endofcontext|>"],
|
| 28 |
description="Passing in a task-oriented dialogue context generates a belief state, actions to take and a response based on those actions",
|
| 29 |
)
|
| 30 |
+
|
| 31 |
+
iface.launch()
|