Spaces:
Runtime error
Runtime error
Commit
·
d311eed
1
Parent(s):
6b4a273
added sentiment analysis
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
|
4 |
pipe_fine = pipeline(model="zeihers-mart/whisper-small-swedish-basic", device_map="auto")
|
5 |
pipe_raw = pipeline(model="openai/whisper-small", device_map="auto")
|
|
|
6 |
|
7 |
# force swedish
|
8 |
pipe_fine.model.config.forced_decoder_ids = (
|
@@ -22,13 +23,18 @@ def transcribe(audio):
|
|
22 |
print(f"Audio transcribed: {text_sv}")
|
23 |
text_raw= pipe_raw(audio)["text"]
|
24 |
print(f"Text translated: {text_raw}")
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
iface = gr.Interface(
|
28 |
fn=transcribe,
|
29 |
inputs=gr.Audio(sources=["microphone"], type="filepath"),
|
30 |
outputs=[gr.Textbox(label="Fine-tuned transcription"),
|
31 |
-
gr.Textbox(label="Whisper
|
|
|
32 |
title="Finetuned Whisper Swedish Small",
|
33 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
34 |
)
|
|
|
3 |
|
4 |
pipe_fine = pipeline(model="zeihers-mart/whisper-small-swedish-basic", device_map="auto")
|
5 |
pipe_raw = pipeline(model="openai/whisper-small", device_map="auto")
|
6 |
+
sa = pipeline('sentiment-analysis', model='marma/bert-base-swedish-cased-sentiment')
|
7 |
|
8 |
# force swedish
|
9 |
pipe_fine.model.config.forced_decoder_ids = (
|
|
|
23 |
print(f"Audio transcribed: {text_sv}")
|
24 |
text_raw= pipe_raw(audio)["text"]
|
25 |
print(f"Text translated: {text_raw}")
|
26 |
+
sentiment= sa(text_sv)["label"]
|
27 |
+
path = "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/1200px-SNice.svg.png"
|
28 |
+
if sentiment == "NEGATIVE":
|
29 |
+
path = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Sad_smiley_yellow_simple.svg/2048px-Sad_smiley_yellow_simple.svg.png"
|
30 |
+
return text_sv, text_raw, path
|
31 |
|
32 |
iface = gr.Interface(
|
33 |
fn=transcribe,
|
34 |
inputs=gr.Audio(sources=["microphone"], type="filepath"),
|
35 |
outputs=[gr.Textbox(label="Fine-tuned transcription"),
|
36 |
+
gr.Textbox(label="Whisper transcription"),
|
37 |
+
gr.Image(label="Sentiment from Fine-tuned transcription", width=100, height=100)],
|
38 |
title="Finetuned Whisper Swedish Small",
|
39 |
description="Realtime demo for Swedish speech recognition using a fine-tuned Whisper small model.",
|
40 |
)
|