File size: 3,087 Bytes
8761bda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c25229
8761bda
1c25229
 
f18b1ee
 
 
 
 
 
8761bda
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
from gradio_client import Client, handle_file
import os

client = Client(f"ahmedJaafari/{os.getenv('PRIVATE_REPO_ID')}", hf_token=os.getenv('HF_TOKEN'))

# Function to make the API call and return the result
def verify_speakers(audio1, audio2):
    result = client.predict(
        audio1=handle_file(audio1),
        audio2=handle_file(audio2),
        api_name="/predict"
    )  
    # Assuming result is a confidence score between 0 and 100
    if result > 75:
        return "<div style='text-align: center;'><h2 style='color:green;'>Speakers are similar</h2></div>"
    else:
        return "<div style='text-align: center;'><h2 style='color:red;'>Speakers are not similar</h2></div>"

# Define the interface for file upload tab
with gr.Blocks() as file_upload_interface:
    with gr.Tab("File Upload"):
        with gr.Row():  # Align inputs in a single column
            audio1_upload = gr.Audio(type="filepath", label="Upload First Audio File")
            audio2_upload = gr.Audio(type="filepath", label="Upload Second Audio File")
        result_file_upload = gr.HTML(label="Result", elem_id="result_html")
        submit_button_file = gr.Button("Submit")
        submit_button_file.click(fn=verify_speakers, inputs=[audio1_upload, audio2_upload], outputs=result_file_upload)

# Define the interface for microphone tab
with gr.Blocks() as microphone_interface:
    with gr.Tab("Microphone Input"):
        with gr.Row():  # Align inputs in a single column
            audio1_mic = gr.Microphone(type="filepath", label="Record First Audio")
            audio2_mic = gr.Microphone(type="filepath", label="Record Second Audio")
        result_mic = gr.HTML(label="Result", elem_id="result_html_mic")
        submit_button_mic = gr.Button("Submit")
        submit_button_mic.click(fn=verify_speakers, inputs=[audio1_mic, audio2_mic], outputs=result_mic)

# Combine both interfaces into tabs
with gr.Blocks(css=".gradio-container { text-align: center; } .image-container {display: flex; justify-content: center; align-items: center;} ") as app:  # Center the container
    gr.Markdown("""
    <div class='image-container'>
        <img src='https://storage.googleapis.com/storage-annarabic/IH%20logo.jpg' alt='IRON HORSE Logo' width='300'/>
    </div>

    # Cord by Annarabic - Speaker Verification Tool
    
    This tool, distributed by **IRON HORSE**, allows you to verify if two speakers are the same by either uploading audio files or recording audio directly using your microphone.
    
    After submission, the system will analyze the recordings and determine if the speakers are similar.

    If you have any questions or would like to learn more, feel free to reach out at [contact@annarabic.com](mailto:contact@annarabic.com) or visit our website at [www.annarabic.com](https://www.annarabic.com).
    """)
    with gr.Tabs():
        with gr.TabItem("Upload Audio Files"):
            file_upload_interface.render()
        with gr.TabItem("Record Using Microphone"):
            microphone_interface.render()

# Launch the Gradio app
app.launch()