Spaces:
Sleeping
Sleeping
Commit
·
5a9e3df
1
Parent(s):
42b3bbc
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,36 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
|
7 |
iface = gr.Interface(
|
8 |
fn=transcribe,
|
|
|
1 |
+
import whisper
|
2 |
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
|
6 |
+
model = whisper.load_model("base")
|
7 |
+
sentiment_analysis = pipeline("sentiment-analysis",model="siebert/sentiment-roberta-large-english")
|
8 |
+
|
9 |
+
def process_audio_file(file):
|
10 |
+
with open(file, "rb") as f:
|
11 |
+
inputs = f.read()
|
12 |
+
|
13 |
+
audio = ffmpeg_read(inputs, sampling_rate)
|
14 |
+
return audio
|
15 |
+
|
16 |
+
|
17 |
+
def transcribe(Microphone, File_Upload):
|
18 |
+
warn_output = ""
|
19 |
+
if (Microphone is not None) and (File_Upload is not None):
|
20 |
+
warn_output = "WARNING: You've uploaded an audio file and used the microphone. " \
|
21 |
+
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
22 |
+
file = Microphone
|
23 |
+
|
24 |
+
elif (Microphone is None) and (File_Upload is None):
|
25 |
+
return "ERROR: You have to either use the microphone or upload an audio file"
|
26 |
+
|
27 |
+
elif Microphone is not None:
|
28 |
+
file = Microphone
|
29 |
+
else:
|
30 |
+
file = File_Upload
|
31 |
|
32 |
+
result = model.transcribe(file, task="translate")
|
33 |
+
return sentiment_analysis(result['text'])
|
34 |
|
35 |
iface = gr.Interface(
|
36 |
fn=transcribe,
|