Spaces:
Sleeping
Sleeping
eaglelandsonce
commited on
Commit
•
651ae26
1
Parent(s):
87359bb
Update app.py
Browse files
app.py
CHANGED
@@ -8,39 +8,53 @@ model = whisper.load_model("base")
|
|
8 |
summarizer = pipeline("summarization")
|
9 |
|
10 |
def get_audio(url):
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
return a
|
19 |
|
20 |
def get_text(url):
|
21 |
-
|
22 |
-
|
23 |
|
24 |
def get_summary(url):
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
30 |
with gr.Blocks() as demo:
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
with gr.
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
result_button.click(get_summary, inputs = input_text, outputs = output_text)
|
45 |
-
result_button_1.click(get_text, inputs = input_text_1, outputs = output_text_1)
|
46 |
demo.launch(debug=True)
|
|
|
8 |
summarizer = pipeline("summarization")
|
9 |
|
10 |
def get_audio(url):
|
11 |
+
yt = YouTube(url)
|
12 |
+
video = yt.streams.filter(only_audio=True).first()
|
13 |
+
out_file = video.download(output_path=".")
|
14 |
+
base, ext = os.path.splitext(out_file)
|
15 |
+
new_file = base + '.mp3'
|
16 |
+
os.rename(out_file, new_file)
|
17 |
+
return new_file
|
|
|
18 |
|
19 |
def get_text(url):
|
20 |
+
result = model.transcribe(get_audio(url))
|
21 |
+
return result['text']
|
22 |
|
23 |
def get_summary(url):
|
24 |
+
article = get_text(url)
|
25 |
+
b = summarizer(article)
|
26 |
+
b = b[0]['summary_text']
|
27 |
+
return b
|
28 |
+
|
29 |
+
def handle_file(file):
|
30 |
+
# Mock function to handle uploaded files
|
31 |
+
return f"Received {file.name} of type {file.type}"
|
32 |
+
|
33 |
with gr.Blocks() as demo:
|
34 |
+
gr.Markdown("<h1><center>Youtube video transcription with OpenAI's Whisper</center></h1>")
|
35 |
+
gr.Markdown("<center>Enter the link of any youtube video to get the transcription of the video and a summary of the video in the form of text.</center>")
|
36 |
+
|
37 |
+
with gr.Tab('Get the transcription of any Youtube video'):
|
38 |
+
with gr.Row():
|
39 |
+
input_text_1 = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
|
40 |
+
output_text_1 = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
|
41 |
+
result_button_1 = gr.Button('Get Transcription')
|
42 |
+
|
43 |
+
with gr.Tab('Summary of Youtube video'):
|
44 |
+
with gr.Row():
|
45 |
+
input_text = gr.Textbox(placeholder='Enter the Youtube video URL', label='URL')
|
46 |
+
output_text = gr.Textbox(placeholder='Summary text of the Youtube Video', label='Summary')
|
47 |
+
result_button = gr.Button('Get Summary')
|
48 |
+
|
49 |
+
# Adding the new tab for drag and drop
|
50 |
+
with gr.Tab('Upload .doc, .txt, .csv files'):
|
51 |
+
with gr.Row():
|
52 |
+
file_input = gr.File(label="Drag & Drop File", type=[".doc", ".txt", ".csv"])
|
53 |
+
file_output = gr.Textbox(placeholder='File received', label='File Info')
|
54 |
+
file_button = gr.Button('Upload File')
|
55 |
+
|
56 |
+
result_button.click(get_summary, inputs=input_text, outputs=output_text)
|
57 |
+
result_button_1.click(get_text, inputs=input_text_1, outputs=output_text_1)
|
58 |
+
file_button.click(handle_file, inputs=file_input, outputs=file_output)
|
59 |
|
|
|
|
|
60 |
demo.launch(debug=True)
|