Spaces:
Sleeping
Sleeping
File size: 1,932 Bytes
d5c679f e199ffc d5c679f e199ffc d5c679f e199ffc d5c679f e199ffc d5c679f e199ffc d5c679f e199ffc 133d361 d5c679f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
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()
|