Spaces:
Running
Running
gorkemgoknar
commited on
Commit
•
3bd1216
1
Parent(s):
8b18457
Update app.py
Browse files
app.py
CHANGED
@@ -92,8 +92,10 @@ def get_chat_response(name,history=[], input_txt = "Hello , what is your name?")
|
|
92 |
|
93 |
def greet(character,message):
|
94 |
|
|
|
|
|
95 |
#gradios set_state/get_state does not persist session for now using global
|
96 |
-
global history
|
97 |
|
98 |
if history["character"] != character:
|
99 |
#switching character
|
@@ -103,7 +105,9 @@ def greet(character,message):
|
|
103 |
response = get_chat_response(character,history=history["message_history"],input_txt=message)
|
104 |
|
105 |
history["message_history"].append((message, response))
|
106 |
-
|
|
|
|
|
107 |
html = "<div class='chatbot'>"
|
108 |
for user_msg, resp_msg in history["message_history"]:
|
109 |
html += f"<div class='user_msg'>You: {user_msg}</div>"
|
@@ -134,7 +138,7 @@ description = "Chat with your favorite movie characters. This space demo has sim
|
|
134 |
#History not implemented in this demo, use metayazar.com/chatbot for a movie and character dropdown chat interface
|
135 |
##interface = gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], title=title, description=description, outputs="text")
|
136 |
|
137 |
-
history = {"character": "None", "message_history" : [] }
|
138 |
interface= gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], outputs="html",css=css, title=title, description=description)
|
139 |
|
140 |
|
|
|
92 |
|
93 |
def greet(character,message):
|
94 |
|
95 |
+
#gradios set_state/get_state had problems on embedded html!
|
96 |
+
history = gr.get_state() or {"character": character, "message_history" : [] }
|
97 |
#gradios set_state/get_state does not persist session for now using global
|
98 |
+
#global history
|
99 |
|
100 |
if history["character"] != character:
|
101 |
#switching character
|
|
|
105 |
response = get_chat_response(character,history=history["message_history"],input_txt=message)
|
106 |
|
107 |
history["message_history"].append((message, response))
|
108 |
+
gr.set_state(history)
|
109 |
+
|
110 |
+
|
111 |
html = "<div class='chatbot'>"
|
112 |
for user_msg, resp_msg in history["message_history"]:
|
113 |
html += f"<div class='user_msg'>You: {user_msg}</div>"
|
|
|
138 |
#History not implemented in this demo, use metayazar.com/chatbot for a movie and character dropdown chat interface
|
139 |
##interface = gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], title=title, description=description, outputs="text")
|
140 |
|
141 |
+
#history = {"character": "None", "message_history" : [] }
|
142 |
interface= gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], outputs="html",css=css, title=title, description=description)
|
143 |
|
144 |
|