gorkemgoknar commited on
Commit
a594ec2
1 Parent(s): ef5c315

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -86,25 +86,20 @@ def get_chat_response(name,history=[], input_txt = "Hello , what is your name?")
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>"
@@ -112,6 +107,8 @@ def greet(character,message):
112
  html += "</div>"
113
 
114
  return html
 
 
115
 
116
  personality_choices = ["Gandalf", "Riddick", "Macleod", "Morpheus", "Neo","Spock","Vader","Indy"]
117
 
@@ -133,7 +130,7 @@ description = "Chat with your favorite movie characters. This space demo has sim
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
 
 
86
 
87
 
88
 
 
89
  def greet(character,message):
90
+
91
+ #gradios set_state/get_state does not persist session for now using global
92
+ global 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
+
101
  history["message_history"].append((message, response))
102
 
 
 
 
 
103
  html = "<div class='chatbot'>"
104
  for user_msg, resp_msg in history["message_history"]:
105
  html += f"<div class='user_msg'>You: {user_msg}</div>"
 
107
  html += "</div>"
108
 
109
  return html
110
+
111
+
112
 
113
  personality_choices = ["Gandalf", "Riddick", "Macleod", "Morpheus", "Neo","Spock","Vader","Indy"]
114
 
 
130
  #History not implemented in this demo, use metayazar.com/chatbot for a movie and character dropdown chat interface
131
  ##interface = gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], title=title, description=description, outputs="text")
132
 
133
+ history = {"character": "None", "message_history" : [] }
134
  interface= gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown(personality_choices) ,"text"], outputs="html",css=css, title=title, description=description)
135
 
136