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 "

Speakers are similar

" else: return "

Speakers are not similar

" # 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; }") as app: # Center the container gr.Markdown("""
IRON HORSE Logo
# 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()