ASG Models commited on
Commit
9ab3574
·
verified ·
1 Parent(s): 8fc7059

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -42
app.py CHANGED
@@ -37,51 +37,55 @@ def get_answer_ai(text):
37
  response = AI.send_message(text)
38
  return response.text
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- text_input = gr.Textbox(label="ُEnter any text")
42
- user_audio = gr.Audio(label="Your Speech")
43
- ai_audio = gr.Audio(label="AI Response Speech")
44
- ai_text = gr.Textbox(label="AI Response Text")
45
 
46
- model_choices = gr.Dropdown(
47
- choices=["asg2024/vits-ar-sa", "asg2024/vits-ar-sa-huba", "asg2024/vits-ar-sa-ms","asg2024/vits-ar-sa-magd","asg2024/vits-ar-sa-fahd"], # Replace with your model names
48
- label="Choose Model",
49
- value="asg2024/vits-ar-sa" # Default selection
50
- )
51
-
52
- def reverse_audio(text,model_choice):
53
- API_URL = f"https://api-inference.huggingface.co/models/{model_choice}"
54
- text_answer=get_answer_ai(text)
55
- dataq = query(text,API_URL)
56
- text_answer=remove_extra_spaces(text_answer)
57
- dataa = query(text_answer,API_URL)
58
-
59
- # data_enhanc = remove_noise_enhance(data)
60
 
61
-
62
- return dataq,dataa,text_answer#(16000, np.flipud(data))
 
 
 
63
 
64
- def reverse_audio_2(text,model_choice):
65
- API_URL = f"https://api-inference.huggingface.co/models/{model_choice}"
66
- text_answer=get_answer_ai(text)
67
- text_answer=remove_extra_spaces(text_answer)
68
- dataa = query(text_answer,API_URL)
69
- return dataa
70
-
71
- demo = gr.Interface(
72
- fn=reverse_audio,
73
- inputs=[text_input,model_choices],
74
- outputs=[user_audio,ai_audio,ai_text],
75
- title=" محادثة صوتية بالذكاء الاصطناعي باللهجة السعودية "
76
- )
77
 
78
- # panal_2 = gr.Interface(
79
- # fn=reverse_audio_2,
80
- # inputs=[text_input,model_choices],
81
- # outputs=[ai_audio],
82
- # title=" محادثة صوتية بالذكاء الاصطناعي باللهجة السعودية "
83
- # )
84
-
85
- # demo = gr.TabbedInterface([panal_1, panal_2],['panal_1', 'panal_2'])
86
  if __name__ == "__main__":
87
- demo.launch()
 
37
  response = AI.send_message(text)
38
  return response.text
39
 
40
+ with gr.Blocks() as demo: # Use gr.Blocks to wrap the entire interface
41
+ with gr.Tab("محادثة صوتية بالذكاء الاصطناعي باللهجة السعودية"):
42
+ with gr.Row(): # Arrange input/output components side-by-side
43
+ with gr.Column():
44
+ text_input = gr.Textbox(label="أدخل أي نص")
45
+ user_audio = gr.Audio(label="صوتك")
46
+ with gr.Column():
47
+ model_choices = gr.Dropdown(
48
+ choices=[
49
+ "asg2024/vits-ar-sa",
50
+ "asg2024/vits-ar-sa-huba",
51
+ "asg2024/vits-ar-sa-ms",
52
+ "asg2024/vits-ar-sa-magd",
53
+ "asg2024/vits-ar-sa-fahd",
54
+ ],
55
+ label="اختر النموذج",
56
+ value="asg2024/vits-ar-sa",
57
+ )
58
+ ai_audio = gr.Audio(label="رد الذكاء الاصطناعي الصوتي")
59
+ ai_text = gr.Textbox(label="رد الذكاء الاصطناعي النصي")
60
 
61
+ btn = gr.Button("إرسال")
 
 
 
62
 
63
+ # Use a single button to trigger both functionalities
64
+ def process_audio(text, model_choice, generate_user_audio=True):
65
+ API_URL = f"https://api-inference.huggingface.co/models/{model_choice}"
66
+ text_answer = get_answer_ai(text)
67
+ text_answer = remove_extra_spaces(text_answer)
68
+ data_ai = query(text_answer, API_URL)
69
+ if generate_user_audio: # Generate user audio if needed
70
+ data_user = query(text, API_URL)
71
+ return data_user, data_ai, text_answer
72
+ else:
73
+ return None, data_ai, text_answer # Return None for user_audio
 
 
 
74
 
75
+ btn.click(
76
+ process_audio, # Call the combined function
77
+ inputs=[text_input, model_choices],
78
+ outputs=[user_audio, ai_audio, ai_text],
79
+ )
80
 
81
+ # Additional button to generate only AI audio
82
+ with gr.Row():
83
+ btn_ai_only = gr.Button("توليد رد الذكاء الاصطناعي فقط")
84
+ btn_ai_only.click(
85
+ lambda text, model_choice: process_audio(text, model_choice, False),
86
+ inputs=[text_input, model_choices],
87
+ outputs=[ai_audio],
88
+ )
 
 
 
 
 
89
 
 
 
 
 
 
 
 
 
90
  if __name__ == "__main__":
91
+ demo.launch()