Spaces:
Sleeping
Sleeping
| 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() | |