gorkemgoknar commited on
Commit
6cb21ba
1 Parent(s): bf58e82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -8
app.py CHANGED
@@ -127,8 +127,7 @@ def greet(character,your_voice,message,history):
127
 
128
 
129
  response = get_chat_response(character,history=history["message_history"],input_txt=message)
130
- if your_voice is not None:
131
- os.system('tts --text "'+response+'" --model_name tts_models/multilingual/multi-dataset/your_tts --speaker_wav '+your_voice+' --language_idx "en"')
132
 
133
  history["message_history"].append((message, response))
134
 
@@ -139,12 +138,36 @@ def greet(character,your_voice,message,history):
139
  html += f"<div class='user_msg'>You: {user_msg}</div>"
140
  html += f"<div class='resp_msg'>{character}: {resp_msg}</div>"
141
  html += "</div>"
142
- if your_voice is None:
143
- return html,history
144
- else:
145
- return html,history,"tts_output.wav"
 
 
 
 
 
 
146
 
 
 
 
 
 
 
 
 
 
 
147
 
 
 
 
 
 
 
 
 
148
 
149
  personality_choices = ["Gandalf", "Riddick", "Macleod", "Morpheus", "Neo","Spock","Vader","Indy"]
150
 
@@ -185,9 +208,8 @@ interface_file= gr.Interface(fn=greet,
185
  "state"],
186
  outputs=["html","state",gr.outputs.Audio(type="file")],
187
  css=css, title=title, description=description,article=article )
188
- interface_text= gr.Interface(fn=greet,
189
  inputs=[gr.inputs.Dropdown(personality_choices),
190
- None,
191
  "text",
192
  "state"],
193
  outputs=["html","state"],
 
127
 
128
 
129
  response = get_chat_response(character,history=history["message_history"],input_txt=message)
130
+ os.system('tts --text "'+response+'" --model_name tts_models/multilingual/multi-dataset/your_tts --speaker_wav '+your_voice+' --language_idx "en"')
 
131
 
132
  history["message_history"].append((message, response))
133
 
 
138
  html += f"<div class='user_msg'>You: {user_msg}</div>"
139
  html += f"<div class='resp_msg'>{character}: {resp_msg}</div>"
140
  html += "</div>"
141
+
142
+ return html,history,"tts_output.wav"
143
+
144
+
145
+ def greet_textonly(character,message,history):
146
+
147
+ #gradios set_state/get_state had problems on embedded html!
148
+ history = history or {"character": character, "message_history" : [] }
149
+ #gradios set_state/get_state does not persist session for now using global
150
+ #global history
151
 
152
+ if history["character"] != character:
153
+ #switching character
154
+ history = {"character": character, "message_history" : [] }
155
+
156
+
157
+ response = get_chat_response(character,history=history["message_history"],input_txt=message)
158
+
159
+ history["message_history"].append((message, response))
160
+
161
+ #emotion = get_emotion(response)
162
 
163
+ html = "<div class='chatbot'>"
164
+ for user_msg, resp_msg in history["message_history"]:
165
+ html += f"<div class='user_msg'>You: {user_msg}</div>"
166
+ html += f"<div class='resp_msg'>{character}: {resp_msg}</div>"
167
+ html += "</div>"
168
+
169
+ return html,history
170
+
171
 
172
  personality_choices = ["Gandalf", "Riddick", "Macleod", "Morpheus", "Neo","Spock","Vader","Indy"]
173
 
 
208
  "state"],
209
  outputs=["html","state",gr.outputs.Audio(type="file")],
210
  css=css, title=title, description=description,article=article )
211
+ interface_text= gr.Interface(fn=greet_textonly,
212
  inputs=[gr.inputs.Dropdown(personality_choices),
 
213
  "text",
214
  "state"],
215
  outputs=["html","state"],