import sys import requests import re import os import base64 import gradio as gr api_token1="Bearer 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" headers1= {"Authorization":api_token1} API_URL = "https://api-inference.huggingface.co/models/jonatasgrosman/wav2vec2-large-xlsr-53-arabic" def query(filename): with open(filename, "rb") as f: data = f.read() # Convert bytes to base64-encoded string encoded_data = base64.b64encode(data).decode() options = {"wait_for_model": True} # Set wait_for_model parameter to True payload = {"inputs": encoded_data, "options": options} response = requests.post(API_URL, headers=headers1, json=payload) return response.json() def process_audio(filename): response = query(filename) o1 = response['text'] return o1 # Define the Gradio interface demo = gr.Interface( fn=process_audio, inputs=gr.inputs.Audio(source="upload", type="filepath"), outputs="text" ) # Launch the Gradio interface demo.launch(share=True)