Spaces:
Sleeping
Sleeping
import os | |
import tempfile | |
import gradio as gr | |
from groq import Groq | |
from hf import hf_transcript, get_whisper_hf_client | |
from logs import configure_logging | |
from remote_llm import summarize | |
from transcribe import parse_audio, get_full_transcript, groq_transcript | |
def gradio_pipeline(video: str, whisper_inference, groq_api_token): | |
groq_client = Groq(api_key=groq_api_token) | |
hf_client = get_whisper_hf_client() | |
print(repr(video)) | |
with tempfile.TemporaryDirectory() as tmpdirname: | |
if video.endswith(".mp4"): | |
parse_audio(video, os.path.join(tmpdirname, "audio.mp3")) | |
elif video.endswith(".mp3"): | |
os.replace(video, os.path.join(tmpdirname, "audio.mp3")) | |
else: | |
gr.Error("Unsupported file type") | |
if whisper_inference == "hf": | |
transcript = get_full_transcript(tmpdirname, hf_client, one_file_transcript_func=hf_transcript) | |
elif whisper_inference == "groq": | |
transcript = get_full_transcript(tmpdirname, groq_client, one_file_transcript_func=groq_transcript) | |
return summarize(transcript, groq_client) | |
if __name__ == "__main__": | |
configure_logging() | |
demo = gr.Interface( | |
fn=gradio_pipeline, | |
title="Video summarizer", | |
inputs=[ | |
gr.File(file_types=[".mp4", ".mp3"], label="Video or audio"), | |
gr.Radio(choices=["groq", "hf"], value="hf", label="Whisper inference"), | |
gr.Text(max_lines=1, type="password", | |
placeholder="Enter your groq API key", | |
label="groq API key") | |
], | |
outputs=gr.Markdown( | |
value="# Here will be the summary...", | |
label="Summary", | |
show_copy_button=True, | |
), | |
examples=[ | |
["examples/mipt.mp4"], | |
["examples/audio.mp3"], | |
], | |
cache_examples=False, | |
allow_flagging="never") | |
demo.launch() | |