Skip to content

Commit

Permalink
hotfix: Support longer videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush committed Nov 16, 2023
1 parent b119cfb commit f65f844
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions applications/talk-with-youtube-gpt4-vision-api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,28 @@ def base64_converter(video_path):


def prompting(base64Frames, openai_key):
# if len(base64Frames)< 10:
# base64Frames = base64Frames
# elif len(base64Frames) < 100:
# base64Frames = base64Frames[0::10]
# elif len(base64Frames) < 1000:
# base64Frames = base64Frames[0::100]
# elif len(base64Frames) < 10000:
# base64Frames = base64Frames[0::1000]
# else:
# st.error('Video is too large to handle by GPT4 Vision API', icon="🚨")

if len(base64Frames)< 5000:
base64Frames = base64Frames[::50]
elif len(base64Frames) < 10000:
base64Frames = base64Frames[::100]
elif len(base64Frames) < 100000:
base64Frames = base64Frames[::10000]
else:
st.error('Video is too large to handle by GPT4 Vision API', icon="🚨")
base64Frames = base64Frames[:50] if len(base64Frames) > 50 else base64Frames
PROMPT_MESSAGES = [
{
"role": "user",
"content": [
"These are frames from a video that I want to upload. Generate a description so that I can get all the information about video to chat with it.",
*map(lambda x: {"image": x, "resize": 360}, base64Frames[::50]),],},]
*map(lambda x: {"image": x, "resize": 756}, base64Frames),],},]

params = {
"model": "gpt-4-vision-preview",
"messages": PROMPT_MESSAGES,
"api_key": openai_key,
"headers": {"Openai-Version": "2020-11-07"},
"max_tokens": 200,
"max_tokens": 300,
}

result = openai.ChatCompletion.create(**params)
Expand Down

0 comments on commit f65f844

Please sign in to comment.