ASG Models commited on
Commit
d28f8b7
·
verified ·
1 Parent(s): ef68d30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py CHANGED
@@ -175,9 +175,35 @@ def get_answer_ai(text):
175
  AI=create_chat_session()
176
  response = AI.send_message(text)
177
  return response.text
 
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  with gr.Blocks() as demo: # Use gr.Blocks to wrap the entire interface
180
 
 
 
 
 
 
 
 
 
181
  with gr.Tab("Chat AI "):
182
  gr.Markdown("## AI: محادثة صوتية بالذكاء الاصطناعي باللهجة السعودية")
183
  with gr.Row(): # Arrange input/output components side-by-side
 
175
  AI=create_chat_session()
176
  response = AI.send_message(text)
177
  return response.text
178
+ chat_history = [] # متغير لتخزين سجل المحادثة
179
 
180
+ def chatbot_fn(input_text, input_audio):
181
+ global chat_history
182
+
183
+ if input_text:
184
+ chat_history.append((input_text, None)) # إضافة رسالة المستخدم
185
+ response_text = get_answer_ai(input_text)
186
+ response_audio = genrate_speech(response_text,'asg2024/vits-ar-sa-huba')
187
+ elif input_audio:
188
+ pass
189
+ # chat_history.append((None, input_audio)) # إضافة رسالة صوتية للمستخدم
190
+ # input_text = convert_speech_to_text(input_audio)
191
+ # response_text = model.generate_response(input_text, chat_history)
192
+ # response_audio = convert_text_to_speech(response_text)
193
+
194
+ chat_history.append((None, response_audio)) # إضافة رد البوت
195
+
196
+ return chat_history
197
  with gr.Blocks() as demo: # Use gr.Blocks to wrap the entire interface
198
 
199
+ with gr.Tab("ChatBot "):
200
+ chatbot = gr.Chatbot(label="محادثة")
201
+ with gr.Row():
202
+ txt = gr.Textbox(label="أدخل رسالتك")
203
+ audio = gr.Audio(sources="microphone", type="filepath")
204
+ txt.change(chatbot_fn, [txt, audio], chatbot)
205
+ audio.change(chatbot_fn, [txt, audio], chatbot)
206
+
207
  with gr.Tab("Chat AI "):
208
  gr.Markdown("## AI: محادثة صوتية بالذكاء الاصطناعي باللهجة السعودية")
209
  with gr.Row(): # Arrange input/output components side-by-side