Spaces:
Sleeping
Sleeping
Commit
·
3fb48f1
1
Parent(s):
d637e75
Update app
Browse files- app.py +39 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
pipe = pipeline(model="matteocirca/whisper-small-it")
|
5 |
+
# pipe = pipeline(model="openai/whisper-small")
|
6 |
+
segments = []
|
7 |
+
def audio2segments(audio,word):
|
8 |
+
global segments
|
9 |
+
if not segments:
|
10 |
+
segments = pipe(audio)["segments"]
|
11 |
+
elif not word:
|
12 |
+
return "No word detected"
|
13 |
+
else:
|
14 |
+
ranges = []
|
15 |
+
for s in segments:
|
16 |
+
if word in s['text'].replace(',',' , ').split(" "):
|
17 |
+
ranges.append((s['start'],s['end']))
|
18 |
+
res = ""
|
19 |
+
for i,r in enumerate(ranges):
|
20 |
+
res += f"{i}) {r[0]}-{r[1]}\n "
|
21 |
+
return res
|
22 |
+
|
23 |
+
|
24 |
+
def find_segment():
|
25 |
+
global segments
|
26 |
+
res = ""
|
27 |
+
|
28 |
+
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=audio2segments,
|
31 |
+
inputs=[gr.Audio(sources=["microphone"], type="filepath"),"text"],
|
32 |
+
outputs="text",
|
33 |
+
title="Whisper Small Italian",
|
34 |
+
description="Realtime demo for Italian speech recognition using a fine-tuned Whisper small model.",
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
+
iface.launch()
|
39 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|