fix: update code
Browse files- app.py +18 -28
- requirements.txt +0 -0
app.py
CHANGED
@@ -1,37 +1,27 @@
|
|
1 |
-
from transformers import
|
2 |
import gradio as gr
|
3 |
-
import time
|
4 |
-
import torch
|
5 |
-
import soundfile as sf
|
6 |
import requests
|
7 |
import os
|
8 |
|
9 |
-
|
10 |
-
token = os.environ['apikey']
|
11 |
-
headers = {"Authorization": token}
|
12 |
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
-
# Load model from HuggingFace Hub
|
18 |
-
with open(audio, "rb") as f:
|
19 |
-
data = f.read()
|
20 |
-
response = requests.post(API_URL, headers=headers, data=data)
|
21 |
-
output = response.json()["text"]
|
22 |
-
state += output + " "
|
23 |
-
return state, state
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
fn=transcribe,
|
28 |
-
inputs=[
|
29 |
-
gr.Audio(source="microphone", type="filepath", streaming=True),
|
30 |
-
"state"
|
31 |
-
],
|
32 |
-
outputs=[
|
33 |
-
"textbox",
|
34 |
-
"state"
|
35 |
-
],
|
36 |
-
live=True).launch(share=True)
|
37 |
-
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
import requests
|
4 |
import os
|
5 |
|
6 |
+
transcriber = pipeline("automatic-speech-recognition", model="omarxadel/hubert-large-arabic-egyptian")
|
|
|
|
|
7 |
|
8 |
+
def transcribe(stream, new_chunk):
|
9 |
+
sr, y = new_chunk
|
10 |
+
y = y.astype(np.float32)
|
11 |
+
y /= np.max(np.abs(y))
|
12 |
|
13 |
+
if stream is not None:
|
14 |
+
stream = np.concatenate([stream, y])
|
15 |
+
else:
|
16 |
+
stream = y
|
17 |
+
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
demo = gr.Interface(
|
21 |
+
transcribe,
|
22 |
+
["state", gr.Audio(source="microphone", streaming=True)],
|
23 |
+
["state", "text"],
|
24 |
+
live=True,
|
25 |
+
)
|
26 |
|
27 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|