Spaces:
Runtime error
Runtime error
import gradio as gr | |
from textblob import TextBlob | |
import utils | |
import tempfile | |
def answer_video_question(query : str, url : str, file : bytes) -> dict: | |
# Either `file` or `url` must be provided | |
if file is not None: | |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_vid: | |
temp_vid.write(file.read()) | |
temp_video_path = temp_vid.name | |
# Output frame folder | |
check = extract_keyframes(temp_video_path) | |
return {"status_vid_frame_from_file":check} | |
elif url: | |
files_path = download_video(url) | |
check = extract_keyframes(files_path['video_path']) | |
return {"out_vid_path_from_url":check} | |
else: | |
return {"error": "Please provide a movie file or URL."} | |
# Create the Gradio interface | |
demo = gr.Interface( | |
fn=answer_video_question, | |
inputs=[ | |
gr.Textbox(placeholder="Enter Query about the movie", label="Query"), | |
gr.Textbox(placeholder="Paste the URL of the movie", label="Movie URL (optional)"), | |
gr.File(label="Upload Movie File (optional)") | |
], | |
outputs=gr.JSON(), | |
title="Text Sentiment Analysis", | |
description="Ask a question about a movie. You can provide a movie via a URL or by uploading a file. The movie will be cached and deleted when the Space goes to sleep." | |
) | |
# Launch the interface and MCP server | |
if __name__ == "__main__": | |
demo.launch(mcp_server=True) |