Spaces:
Sleeping
Sleeping
Ragnov
commited on
Commit
•
126f94b
1
Parent(s):
989fc3d
add app.py and requirements.txt
Browse files- app.py +89 -0
- requirements.txt.txt +3 -0
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Module Imports
|
2 |
+
from pytube import YouTube
|
3 |
+
import whisper
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
model = whisper.load_model("base.en")
|
7 |
+
|
8 |
+
# Functions
|
9 |
+
def transcribe(file):
|
10 |
+
options = dict(task="transcribe", best_of=5)
|
11 |
+
text = model.transcribe(file, **options)["text"]
|
12 |
+
return text.strip()
|
13 |
+
|
14 |
+
def translate(file):
|
15 |
+
options = dict(task="translate", best_of=5)
|
16 |
+
text = model.transcribe(file, **options)["text"]
|
17 |
+
return text.strip()
|
18 |
+
|
19 |
+
def get_filename(file_obj):
|
20 |
+
return file_obj.orig_name
|
21 |
+
|
22 |
+
def inference(link):
|
23 |
+
yt = YouTube(link)
|
24 |
+
path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
|
25 |
+
options = whisper.DecodingOptions(without_timestamps=True)
|
26 |
+
results = model.transcribe(path)
|
27 |
+
return results['text']
|
28 |
+
|
29 |
+
def populate_metadata(link):
|
30 |
+
yt = YouTube(link)
|
31 |
+
return yt.thumbnail_url, yt.title
|
32 |
+
|
33 |
+
def transcribe_file(file):
|
34 |
+
options = dict(task="transcribe", best_of=5)
|
35 |
+
file = get_filename(file)
|
36 |
+
text = model.transcribe(file, **options)["text"]
|
37 |
+
return text.strip()
|
38 |
+
|
39 |
+
# Gradio Blocks
|
40 |
+
demo = gr.Blocks()
|
41 |
+
with demo:
|
42 |
+
gr.Markdown(""" <p style="text-align: center;"> Speech To Text Grammar Checker </p>""")
|
43 |
+
with gr.Tabs():
|
44 |
+
with gr.TabItem("Voice Record"):
|
45 |
+
with gr.Row():
|
46 |
+
audio = gr.Audio(show_label=False,source="microphone",type="filepath")
|
47 |
+
text_output1 = gr.Textbox(label="Transcription", placeholder="Text Output")
|
48 |
+
transcribe_button1 = gr.Button("Transcribe")
|
49 |
+
CG_button1 = gr.Button("Check Grammar (Work In Progress)")
|
50 |
+
with gr.TabItem("Upload File"):
|
51 |
+
with gr.Row():
|
52 |
+
file_upload = gr.File()
|
53 |
+
text_output2 = gr.Textbox(label="Transcription", placeholder="Text Output")
|
54 |
+
transcribe_button2 = gr.Button("Transcribe")
|
55 |
+
CG_button3 = gr.Button("Check Grammar (Work In Progress)")
|
56 |
+
with gr.TabItem("Youtube Link"):
|
57 |
+
with gr.Box():
|
58 |
+
link = gr.Textbox(label="YouTube Link")
|
59 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
60 |
+
title = gr.Label(label="Video Title", placeholder="Title")
|
61 |
+
img = gr.Image(label="Thumbnail")
|
62 |
+
text_link_output = gr.Textbox(label="Transcription", placeholder="Text Output",lines=5)
|
63 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
64 |
+
transcribe_button3 = gr.Button("Transcribe")
|
65 |
+
CG_button3 = gr.Button("Check Grammar (Work In Progress)")
|
66 |
+
with gr.TabItem("About"):
|
67 |
+
with gr.Row():
|
68 |
+
gr.Markdown("""
|
69 |
+
<p style="text-align: center;"> Thesis System presented by <br/> <br/>
|
70 |
+
• <b>Jomari A. Buenaobra</b> <br/>
|
71 |
+
• <b>Christian G. Eslit</b> <br/>
|
72 |
+
• <b>Daniel L. Espinola</b> <br/>
|
73 |
+
• <b>Jhon Vincent A. Gupo</b> <br/>
|
74 |
+
• <b>Ryan M. Ibay</b> <br/> <br/>
|
75 |
+
In partial fulfillment of the requirements for the degree <br/>
|
76 |
+
Bachelor of Science in Computer Science Specialized in Intelligent Systems <br/>
|
77 |
+
Laguna State Polytechnic University - Los Baños Campus . <br/> <br/>
|
78 |
+
We would also like to thank our fellow adviser and subject specialist for their guidance in making this idea a reality. <br/>
|
79 |
+
• <b>Crisanto F. Gulay</b> - Adviser <br/>
|
80 |
+
• <b>Jonardo R. Asor</b> - Subject Specialist <br/>
|
81 |
+
</p>
|
82 |
+
""")
|
83 |
+
|
84 |
+
link.change(populate_metadata, inputs=[link], outputs=[img, title])
|
85 |
+
transcribe_button1.click(transcribe, inputs=audio, outputs=text_output1)
|
86 |
+
transcribe_button2.click(transcribe_file, inputs=file_upload, outputs=text_output2)
|
87 |
+
transcribe_button3.click(inference, inputs=link, outputs=text_link_output)
|
88 |
+
|
89 |
+
demo.launch()
|
requirements.txt.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/openai/whisper.git
|
2 |
+
gradio
|
3 |
+
pytube
|