Video-Voiceover / app.py
BroBro87's picture
Update app.py
4cb1645 verified
raw
history blame
1.25 kB
import gradio as gr
import google.generativeai as genai
from pathlib import Path
import tempfile
import os
def summarize_video(video_path):
if video_path is None:
return "Please upload a video file."
try:
# Since Gradio passes the path as a string, we can use it directly
# Create the prompt
prompt = "Summarize this video"
# Set up the model
model = genai.GenerativeModel(model_name="models/gemini-1.5-pro", api_key = os.environ['GOOGLE_API_KEY'])
# Make the LLM request
print("Making LLM inference request...")
response = model.generate_content([prompt, video_path],
request_options={"timeout": 2000})
return response.text
except Exception as e:
return f"An error occurred: {str(e)}"
# Create Gradio interface
iface = gr.Interface(
fn=summarize_video,
inputs=gr.Video(label="Upload Video"),
outputs=gr.Textbox(label="Summary", lines=10),
title="Video Summarizer",
description="Upload a video to get an AI-generated summary using Gemini 1.5 Pro.",
examples=[],
cache_examples=False
)
# Launch the interface
if __name__ == "__main__":
iface.launch(share=True)