shreyasiv commited on
Commit
7495ad5
·
verified ·
1 Parent(s): 13f1611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -6,9 +6,14 @@ import time
6
  import tempfile
7
  import base64
8
  import os
9
-
10
-
11
-
 
 
 
 
 
12
  client = OpenAI()
13
 
14
  def extract_recent_frames(video_url, output_folder, duration=10, frames_per_second=1):
@@ -78,7 +83,26 @@ def main():
78
  st.error("Failed to extract frames.")
79
 
80
  #####################33
81
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  #########################################3333
84
 
 
6
  import tempfile
7
  import base64
8
  import os
9
+ from dotenv import load_dotenv
10
+ from openai import OpenAI
11
+ import assemblyai as aai
12
+
13
+ # Load environment variables
14
+ load_dotenv()
15
+ aai.settings.api_key = os.getenv("ASSEMBLYAI_API_KEY")
16
+ OpenAI.api_key = os.getenv("OPENAI_API_KEY")
17
  client = OpenAI()
18
 
19
  def extract_recent_frames(video_url, output_folder, duration=10, frames_per_second=1):
 
83
  st.error("Failed to extract frames.")
84
 
85
  #####################33
86
+ def generate_description(base64_frames):
87
+ try:
88
+ prompt_messages = [
89
+ {
90
+ "role": "user",
91
+ "content": [
92
+ "1. Generate a description for this sequence of video frames in about 90 words. Return the following: 1. List of objects in the video 2. Any restrictive content or sensitive content and if so which frame.",
93
+ *map(lambda x: {"image": x, "resize": 428}, base64_frames[0::30]),
94
+ ],
95
+ },
96
+ ]
97
+ response = client.chat.completions.create(
98
+ model="gpt-4-vision-preview",
99
+ messages=prompt_messages,
100
+ max_tokens=3000,
101
+ )
102
+ return response.choices[0].message.content
103
+ except Exception as e:
104
+ print(f"Error in generate_description: {e}")
105
+ return None
106
 
107
  #########################################3333
108