Spaces:
Running
Running
gorkemgoknar
commited on
Commit
•
7707a25
1
Parent(s):
3a1d7a2
Update app.py
Browse files
app.py
CHANGED
@@ -83,25 +83,59 @@ def get_chat_response(name, input_txt = "Hello , what is your name?",history=[])
|
|
83 |
| Brother | Allnut | Rose | Qui-Gon | Jar Jar
|
84 |
'''
|
85 |
|
86 |
-
def greet(character,input_txt):
|
87 |
-
##add a bootstrap history (item 1 is speaker, item 2 is character)
|
88 |
-
history = ["Who are you?","I am " + character]
|
89 |
-
return get_chat_response(character,history=history,input_txt=input_txt)
|
90 |
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
examples= ["Gandalf", "What is your name?"]
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
|
|
|
|
99 |
title = "Metayazar - Movie Chatbot"
|
100 |
description = "Chat with your favorite movie characters. This space demo has simple interface and no history, test it out in metayazar.com/chatbot for more movie/character options and history memorized."
|
101 |
|
102 |
#History not implemented in this demo, use metayazar.com/chatbot for a movie and character dropdown chat interface
|
103 |
-
interface = gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], title=title, description=description, outputs="text")
|
104 |
|
105 |
|
|
|
|
|
|
|
106 |
if __name__ == "__main__":
|
107 |
interface.launch()
|
|
|
83 |
| Brother | Allnut | Rose | Qui-Gon | Jar Jar
|
84 |
'''
|
85 |
|
|
|
|
|
|
|
|
|
86 |
|
87 |
|
88 |
+
|
89 |
+
|
90 |
+
def greet(character,message):
|
91 |
+
print(gr.get_state())
|
92 |
+
history = gr.get_state() or {"character": character, "message_history" : [] }
|
93 |
+
"""
|
94 |
+
if history["character"] != character:
|
95 |
+
#switching character
|
96 |
+
history = {"character": character, "message_history" : [] }
|
97 |
+
"""
|
98 |
+
|
99 |
+
response = get_chat_response(character,history=history["message_history"],input_txt=message)
|
100 |
+
print(response)
|
101 |
+
|
102 |
+
history["message_history"].append((message, response))
|
103 |
+
|
104 |
+
gr.set_state(history)
|
105 |
+
|
106 |
+
print(history)
|
107 |
+
|
108 |
+
html = "<div class='chatbot'>"
|
109 |
+
for user_msg, resp_msg in history["message_history"]:
|
110 |
+
html += f"<div class='user_msg'>You: {user_msg}</div>"
|
111 |
+
html += f"<div class='resp_msg'>{character}: {resp_msg}</div>"
|
112 |
+
html += "</div>"
|
113 |
+
|
114 |
+
return html
|
115 |
+
|
116 |
+
personality_choices = ["Gandalf", "Riddick", "Macleod", "Morpheus", "Neo","Spock","Vader","Indy"]
|
117 |
|
118 |
examples= ["Gandalf", "What is your name?"]
|
119 |
|
120 |
+
css="""
|
121 |
+
.chatbox {display:flex;flex-direction:column}
|
122 |
+
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
123 |
+
.user_msg {background-color:cornflowerblue;color:white;align-self:start}
|
124 |
+
.resp_msg {background-color:lightgray;align-self:self-end}
|
125 |
+
"""
|
126 |
|
127 |
|
128 |
+
#some selected ones are in for demo use
|
129 |
+
personality_choices = ["Gandalf", "Riddick", "Macleod", "Morpheus", "Neo","Spock","Vader","Indy", "Ig-11","Threepio","Tony Stark","Batman","Vizzini"]
|
130 |
title = "Metayazar - Movie Chatbot"
|
131 |
description = "Chat with your favorite movie characters. This space demo has simple interface and no history, test it out in metayazar.com/chatbot for more movie/character options and history memorized."
|
132 |
|
133 |
#History not implemented in this demo, use metayazar.com/chatbot for a movie and character dropdown chat interface
|
134 |
+
##interface = gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], title=title, description=description, outputs="text")
|
135 |
|
136 |
|
137 |
+
interface= gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], outputs="html",css=css, title=title, description=description)
|
138 |
+
|
139 |
+
|
140 |
if __name__ == "__main__":
|
141 |
interface.launch()
|