Spaces:
Runtime error
Runtime error
first
Browse files- app.py +42 -0
- packages.txt +1 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub.hf_api import HfFolder
|
2 |
+
HfFolder.save_token(os.environ.get("auth_token"))
|
3 |
+
|
4 |
+
from huggingface_hub import Repository
|
5 |
+
import gradio as gr
|
6 |
+
from faster_whisper import WhisperModel
|
7 |
+
import numpy as np
|
8 |
+
import os
|
9 |
+
|
10 |
+
repo = Repository(local_dir="huggingface-hub", clone_from="https://huggingface.co/nadsoft/faster-hamsa")
|
11 |
+
|
12 |
+
file_name = "recording0.wav"
|
13 |
+
# check if the file exists
|
14 |
+
if os.path.exists(file_name):
|
15 |
+
os.remove(file_name)
|
16 |
+
|
17 |
+
transcriber = WhisperModel(repo.local_dir,device="cuda", compute_type="float16")
|
18 |
+
|
19 |
+
def transcribe(stream, new_chunk):
|
20 |
+
sr, y = new_chunk
|
21 |
+
y = y.astype(np.float32)
|
22 |
+
y /= np.max(np.abs(y))
|
23 |
+
|
24 |
+
if stream is not None:
|
25 |
+
stream = np.concatenate([stream, y])
|
26 |
+
else:
|
27 |
+
stream = y
|
28 |
+
|
29 |
+
write("recording0.wav", sr, stream)
|
30 |
+
segments, _ = model.transcribe("recording0.wav", language="ar")
|
31 |
+
segments = list(segments) # The transcription will actually run here
|
32 |
+
return stream, str(segments[0][2])
|
33 |
+
|
34 |
+
|
35 |
+
demo = gr.Interface(
|
36 |
+
transcribe,
|
37 |
+
["state", gr.Audio(sources=["microphone"], streaming=True)],
|
38 |
+
["state", "text"],
|
39 |
+
live=True,
|
40 |
+
)
|
41 |
+
|
42 |
+
demo.launch()
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
libcublas11
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
datasets
|
2 |
+
transformers[torch]
|
3 |
+
transformers
|
4 |
+
faster-whisper @ https://github.com/nyanta012/faster-whisper/archive/refs/heads/master.tar.gz
|
5 |
+
gradio
|