CoolFace
Apppublic

KTO461998/Movie-Recap-Generator

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
app.py43 linesDownload Raw Back to root
1import gradio as gr2import cv23import PIL.Image4import google.generativeai as genai5import os6 7# API Key Configure8genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))9 10def process_recap(video_path):11    # 1. ဗီဒီယိုကို အပိုင်းပိုင်း (၅ စက္ကန့် တစ်ကြိမ်) Frame ယူခြင်း12    cap = cv2.VideoCapture(video_path)13    fps = cap.get(cv2.CAP_PROP_FPS)14    frames = []15    count = 016    while cap.isOpened():17        ret, frame = cap.read()18        if not ret: break19        if count % (int(fps) * 5) == 0: # 5 seconds interval20            rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)21            frames.append(PIL.Image.fromarray(rgb_frame))22        count += 123    cap.release()24    25    # 2. AI သို့ ပို့ခြင်း26    model = genai.GenerativeModel('gemini-1.5-flash')27    prompt = "You are a movie recap expert. Look at these frames from a 2-minute video and write a dramatic, short recap script with a hook."28    29    # Frame တွေကို list အနေနဲ့ ပို့မယ်30    response = model.generate_content([prompt] + frames)31    32    return response.text33 34# Gradio Interface35demo = gr.Interface(36    fn=process_recap,37    inputs=gr.Video(),38    outputs="text",39    title="2-Minute Movie Recap AI"40)41 42demo.launch()43