File size: 1,356 Bytes
bd87b93
18899bc
 
 
 
f6dc7ba
18899bc
 
f6dc7ba
18899bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32b86d6
18899bc
32b86d6
18899bc
 
32b86d6
bd87b93
18899bc
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
import gradio as gr
import cv2
import PIL.Image
import google.generativeai as genai
import os

# API Key Configure
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))

def process_recap(video_path):
    # 1. ဗီဒီယိုကို အပိုင်းပိုင်း (၅ စက္ကန့် တစ်ကြိမ်) Frame ယူခြင်း
    cap = cv2.VideoCapture(video_path)
    fps = cap.get(cv2.CAP_PROP_FPS)
    frames = []
    count = 0
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret: break
        if count % (int(fps) * 5) == 0: # 5 seconds interval
            rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            frames.append(PIL.Image.fromarray(rgb_frame))
        count += 1
    cap.release()
    
    # 2. AI သို့ ပို့ခြင်း
    model = genai.GenerativeModel('gemini-1.5-flash')
    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."
    
    # Frame တွေကို list အနေနဲ့ ပို့မယ်
    response = model.generate_content([prompt] + frames)
    
    return response.text

# Gradio Interface
demo = gr.Interface(
    fn=process_recap,
    inputs=gr.Video(),
    outputs="text",
    title="2-Minute Movie Recap AI"
)

demo.launch()