Spaces:
Sleeping
Sleeping
File size: 1,007 Bytes
e015d06 0a01524 e015d06 |
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 |
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) |