Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
demo = gr.Interface(
|
| 8 |
-
fn=
|
| 9 |
inputs=gr.Video(),
|
| 10 |
-
outputs=
|
| 11 |
-
title="
|
| 12 |
)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import PIL.Image
|
| 4 |
+
import google.generativeai as genai
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
# API Key Configure
|
| 8 |
+
genai.configure(api_key=os.environ.get("GOOGLE_API_KEY"))
|
| 9 |
|
| 10 |
+
def 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 = 0
|
| 16 |
+
while cap.isOpened():
|
| 17 |
+
ret, frame = cap.read()
|
| 18 |
+
if not ret: break
|
| 19 |
+
if count % (int(fps) * 5) == 0: # 5 seconds interval
|
| 20 |
+
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 21 |
+
frames.append(PIL.Image.fromarray(rgb_frame))
|
| 22 |
+
count += 1
|
| 23 |
+
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.text
|
| 33 |
+
|
| 34 |
+
# Gradio Interface
|
| 35 |
demo = gr.Interface(
|
| 36 |
+
fn=process_recap,
|
| 37 |
inputs=gr.Video(),
|
| 38 |
+
outputs="text",
|
| 39 |
+
title="2-Minute Movie Recap AI"
|
| 40 |
)
|
| 41 |
|
| 42 |
+
demo.launch()
|
|
|