Spaces:
Runtime error
Runtime error
jpdiazpardo
commited on
Commit
β’
55a586c
1
Parent(s):
7b2e448
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
|
|
3 |
from icon import generate_icon
|
4 |
from transformers import pipeline
|
5 |
from timestamp import format_timestamp
|
@@ -16,20 +17,30 @@ pipe = pipeline(
|
|
16 |
device=device,
|
17 |
)
|
18 |
|
|
|
|
|
|
|
19 |
def transcribe(file, task, return_timestamps):
|
20 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)
|
21 |
text = outputs["text"]
|
22 |
timestamps = outputs["chunks"]
|
23 |
|
|
|
24 |
if return_timestamps==True:
|
|
|
25 |
timestamps = [f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}" for chunk in timestamps]
|
26 |
-
|
27 |
else:
|
28 |
timestamps = [f"{chunk['text']}" for chunk in timestamps]
|
|
|
29 |
|
30 |
text = "<br>".join(str(feature) for feature in timestamps)
|
31 |
text = f"<h4>Transcription</h4><div style='overflow-y: scroll; height: 250px;'>{text}</div>"
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
inputs = [gr.Audio(source="upload", label="Audio file", type="filepath"),
|
@@ -37,7 +48,8 @@ inputs = [gr.Audio(source="upload", label="Audio file", type="filepath"),
|
|
37 |
gr.Checkbox(value=True, label="Return timestamps")]
|
38 |
|
39 |
outputs = [gr.Audio(label="Processed Audio", type="filepath"),
|
40 |
-
gr.outputs.HTML("text")
|
|
|
41 |
|
42 |
title = "Whisper Demo: Transcribe Audio"
|
43 |
|
@@ -47,7 +59,8 @@ description = ("Transcribe long-form audio inputs with the click of a button! De
|
|
47 |
f" checkpoint [{MODEL_NAME1}](https://huggingface.co/{MODEL_NAME1}) and π€ Transformers to transcribe audio files"
|
48 |
" of arbitrary length. Check some of the 'cool' examples below")
|
49 |
|
50 |
-
examples = [["When a Demon Defiles a Witch.wav","transcribe",True]
|
|
|
51 |
|
52 |
|
53 |
linkedin = generate_icon("linkedin")
|
@@ -58,10 +71,10 @@ article = ("<div style='text-align: center; max-width:800px; margin:10px auto;'>
|
|
58 |
f"{github} <a href='https://github.com/jpdiazpardo' target='_blank'>jpdiazpardo</a></p>"
|
59 |
)
|
60 |
|
|
|
61 |
title = "Scream: Fine-Tuned Whisper model for automatic gutural speech recognition π€π€π€"
|
62 |
|
63 |
-
demo = gr.Interface(title = title, fn=transcribe, inputs = inputs, outputs = outputs, description=description, cache_examples=True,
|
64 |
-
allow_flagging="never", article = article , examples=examples)
|
65 |
|
66 |
demo.queue(concurrency_count=3)
|
67 |
demo.launch(debug = True)
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from charts import spider_chart
|
4 |
from icon import generate_icon
|
5 |
from transformers import pipeline
|
6 |
from timestamp import format_timestamp
|
|
|
17 |
device=device,
|
18 |
)
|
19 |
|
20 |
+
#Define classifier for sentiment analysis
|
21 |
+
classifier = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base", top_k=None)
|
22 |
+
|
23 |
def transcribe(file, task, return_timestamps):
|
24 |
outputs = pipe(file, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)
|
25 |
text = outputs["text"]
|
26 |
timestamps = outputs["chunks"]
|
27 |
|
28 |
+
#If return timestamps is True, return html text with timestamps format
|
29 |
if return_timestamps==True:
|
30 |
+
spider_text = [f"{chunk['text']}" for chunk in timestamps] #Text for spider chart without timestamps
|
31 |
timestamps = [f"[{format_timestamp(chunk['timestamp'][0])} -> {format_timestamp(chunk['timestamp'][1])}] {chunk['text']}" for chunk in timestamps]
|
32 |
+
|
33 |
else:
|
34 |
timestamps = [f"{chunk['text']}" for chunk in timestamps]
|
35 |
+
spider_text = timestamps
|
36 |
|
37 |
text = "<br>".join(str(feature) for feature in timestamps)
|
38 |
text = f"<h4>Transcription</h4><div style='overflow-y: scroll; height: 250px;'>{text}</div>"
|
39 |
+
|
40 |
+
spider_text = "\n".join(str(feature) for feature in spider_text)
|
41 |
+
fig = spider_chart(classifier, spider_text)
|
42 |
+
|
43 |
+
return file, text, fig
|
44 |
|
45 |
|
46 |
inputs = [gr.Audio(source="upload", label="Audio file", type="filepath"),
|
|
|
48 |
gr.Checkbox(value=True, label="Return timestamps")]
|
49 |
|
50 |
outputs = [gr.Audio(label="Processed Audio", type="filepath"),
|
51 |
+
gr.outputs.HTML("text"),
|
52 |
+
gr.Plot(label="fig")]
|
53 |
|
54 |
title = "Whisper Demo: Transcribe Audio"
|
55 |
|
|
|
59 |
f" checkpoint [{MODEL_NAME1}](https://huggingface.co/{MODEL_NAME1}) and π€ Transformers to transcribe audio files"
|
60 |
" of arbitrary length. Check some of the 'cool' examples below")
|
61 |
|
62 |
+
examples = [["When a Demon Defiles a Witch.wav","transcribe",True]
|
63 |
+
["Immaculate Misconception.wav","transcribe", True]]
|
64 |
|
65 |
|
66 |
linkedin = generate_icon("linkedin")
|
|
|
71 |
f"{github} <a href='https://github.com/jpdiazpardo' target='_blank'>jpdiazpardo</a></p>"
|
72 |
)
|
73 |
|
74 |
+
|
75 |
title = "Scream: Fine-Tuned Whisper model for automatic gutural speech recognition π€π€π€"
|
76 |
|
77 |
+
demo = gr.Interface(title = title, fn=transcribe, inputs = inputs, outputs = outputs, description=description, cache_examples=True, allow_flagging="never", article = article , examples=examples)
|
|
|
78 |
|
79 |
demo.queue(concurrency_count=3)
|
80 |
demo.launch(debug = True)
|