Spaces:
Sleeping
Sleeping
ElaaKhazna
commited on
Commit
•
e015d06
1
Parent(s):
b087bd1
Add application file
Browse files- app.py.txt +36 -0
app.py.txt
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import sys
|
3 |
+
import requests
|
4 |
+
import re
|
5 |
+
import os
|
6 |
+
import base64
|
7 |
+
api_token1="Bearer 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"
|
8 |
+
headers1= {"Authorization":api_token1}
|
9 |
+
|
10 |
+
API_URL = "https://api-inference.huggingface.co/models/jonatasgrosman/wav2vec2-large-xlsr-53-arabic"
|
11 |
+
|
12 |
+
def query(filename):
|
13 |
+
with open(filename, "rb") as f:
|
14 |
+
data = f.read()
|
15 |
+
|
16 |
+
# Convert bytes to base64-encoded string
|
17 |
+
encoded_data = base64.b64encode(data).decode()
|
18 |
+
options = {"wait_for_model": True} # Set wait_for_model parameter to True
|
19 |
+
payload = {"inputs": encoded_data, "options": options}
|
20 |
+
response = requests.post(API_URL, headers=headers1, json=payload)
|
21 |
+
|
22 |
+
return response.json()
|
23 |
+
|
24 |
+
def process_audio(filename):
|
25 |
+
response = query(filename)
|
26 |
+
o1 = response['text']
|
27 |
+
return o1
|
28 |
+
# Define the Gradio interface
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=process_audio,
|
31 |
+
inputs=gr.inputs.Audio(source="upload", type="filepath"),
|
32 |
+
outputs="text"
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the Gradio interface
|
36 |
+
demo.launch(share=True)
|