ahmedJaafari commited on
Commit
8761bda
·
verified ·
1 Parent(s): 8c98774

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_client import Client, handle_file
3
+ import os
4
+
5
+ client = Client(f"ahmedJaafari/{os.getenv('PRIVATE_REPO_ID')}", hf_token=os.getenv('HF_TOKEN'))
6
+
7
+ # Function to make the API call and return the result
8
+ def verify_speakers(audio1, audio2):
9
+ result = client.predict(
10
+ audio1=handle_file(audio1),
11
+ audio2=handle_file(audio2),
12
+ api_name="/predict"
13
+ )
14
+ # Assuming result is a confidence score between 0 and 100
15
+ if result > 75:
16
+ return "<div style='text-align: center;'><h2 style='color:green;'>Speakers are similar</h2></div>"
17
+ else:
18
+ return "<div style='text-align: center;'><h2 style='color:red;'>Speakers are not similar</h2></div>"
19
+
20
+ # Define the interface for file upload tab
21
+ with gr.Blocks() as file_upload_interface:
22
+ with gr.Tab("File Upload"):
23
+ with gr.Row(): # Align inputs in a single column
24
+ audio1_upload = gr.Audio(type="filepath", label="Upload First Audio File")
25
+ audio2_upload = gr.Audio(type="filepath", label="Upload Second Audio File")
26
+ result_file_upload = gr.HTML(label="Result", elem_id="result_html")
27
+ submit_button_file = gr.Button("Submit")
28
+ submit_button_file.click(fn=verify_speakers, inputs=[audio1_upload, audio2_upload], outputs=result_file_upload)
29
+
30
+ # Define the interface for microphone tab
31
+ with gr.Blocks() as microphone_interface:
32
+ with gr.Tab("Microphone Input"):
33
+ with gr.Row(): # Align inputs in a single column
34
+ audio1_mic = gr.Microphone(type="filepath", label="Record First Audio")
35
+ audio2_mic = gr.Microphone(type="filepath", label="Record Second Audio")
36
+ result_mic = gr.HTML(label="Result", elem_id="result_html_mic")
37
+ submit_button_mic = gr.Button("Submit")
38
+ submit_button_mic.click(fn=verify_speakers, inputs=[audio1_mic, audio2_mic], outputs=result_mic)
39
+
40
+ # Combine both interfaces into tabs
41
+ with gr.Blocks(css=".gradio-container { text-align: center; }") as app: # Center the container
42
+ gr.Markdown("""
43
+ # Speaker Verification Tool
44
+
45
+ This demo allows you to verify if two speakers are the same by either uploading audio files or recording audio directly using your microphone.
46
+ After submission, the system will analyze the recordings and determine if the speakers are similar.
47
+
48
+ If you have any questions or would like to learn more, feel free to reach out at [[email protected]](mailto:[email protected]) or visit our website at [www.annarabic.com](https://www.annarabic.com).
49
+ """)
50
+ with gr.Tabs():
51
+ with gr.TabItem("Upload Audio Files"):
52
+ file_upload_interface.render()
53
+ with gr.TabItem("Record Using Microphone"):
54
+ microphone_interface.render()
55
+
56
+ # Launch the Gradio app
57
+ app.launch()