Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import time
|
|
7 |
import torch
|
8 |
from transformers import pipeline
|
9 |
import re
|
|
|
10 |
|
11 |
# Initialize the LLM and other components
|
12 |
llm = HuggingFaceEndpoint(
|
@@ -85,7 +86,15 @@ def process_audio(audio_path):
|
|
85 |
classifications.append(f"Sentence: {sentence}\nTopic: {classification}\nLanguage: {lang}\nTime: {duration:.2f}s")
|
86 |
|
87 |
return "\n\n".join(classifications)
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
# Create the Gradio interface
|
90 |
def create_gradio_interface():
|
91 |
with gr.Blocks() as iface:
|
@@ -104,10 +113,14 @@ def create_gradio_interface():
|
|
104 |
|
105 |
with gr.Tab("Audio Input"):
|
106 |
audio_input = gr.Audio(label="Upload Audio", type="filepath")
|
|
|
107 |
audio_output = gr.Textbox(label="Detected Topics from Audio")
|
108 |
audio_submit_btn = gr.Button("Process Audio")
|
109 |
|
110 |
-
|
|
|
|
|
|
|
111 |
|
112 |
iface.launch()
|
113 |
|
|
|
7 |
import torch
|
8 |
from transformers import pipeline
|
9 |
import re
|
10 |
+
from whisperplus import download_youtube_to_mp3
|
11 |
|
12 |
# Initialize the LLM and other components
|
13 |
llm = HuggingFaceEndpoint(
|
|
|
86 |
classifications.append(f"Sentence: {sentence}\nTopic: {classification}\nLanguage: {lang}\nTime: {duration:.2f}s")
|
87 |
|
88 |
return "\n\n".join(classifications)
|
89 |
+
def handle_audio_input(audio_path=None, youtube_url=None):
|
90 |
+
if youtube_url:
|
91 |
+
audio_path = download_youtube_to_mp3(youtube_url, output_dir="downloads", filename="youtube_audio")
|
92 |
+
|
93 |
+
if audio_path:
|
94 |
+
return process_audio(audio_path)
|
95 |
+
else:
|
96 |
+
return "No audio input provided."
|
97 |
+
|
98 |
# Create the Gradio interface
|
99 |
def create_gradio_interface():
|
100 |
with gr.Blocks() as iface:
|
|
|
113 |
|
114 |
with gr.Tab("Audio Input"):
|
115 |
audio_input = gr.Audio(label="Upload Audio", type="filepath")
|
116 |
+
youtube_input = gr.Textbox(label="YT URL (optional)")
|
117 |
audio_output = gr.Textbox(label="Detected Topics from Audio")
|
118 |
audio_submit_btn = gr.Button("Process Audio")
|
119 |
|
120 |
+
def on_audio_submit(audio, youtube_url):
|
121 |
+
return handle_audio_input(audio_path=audio, youtube_url=youtube_url)
|
122 |
+
|
123 |
+
audio_submit_btn.click(fn=on_audio_submit, inputs=[audio_input, youtube_input], outputs=audio_output)
|
124 |
|
125 |
iface.launch()
|
126 |
|