Unggi commited on
Commit
de92875
1 Parent(s): a5a59c1

version1 completed

Browse files
Files changed (3) hide show
  1. requirements.txt +2 -1
  2. src/obs_eval_gradio.py +11 -39
  3. src/temp_video.mp4 +0 -0
requirements.txt CHANGED
@@ -2,4 +2,5 @@ openai
2
  opencv-python
3
  python-dotenv
4
  gradio
5
- opencv-python-headless
 
 
2
  opencv-python
3
  python-dotenv
4
  gradio
5
+ opencv-python-headless
6
+ pytest-shutil
src/obs_eval_gradio.py CHANGED
@@ -2,9 +2,8 @@ import gradio as gr
2
  import cv2
3
  import base64
4
  import openai
5
- import tempfile
6
 
7
- def process_video(video_file, api_key):
8
  # Set the OpenAI API key
9
  openai.api_key = api_key
10
 
@@ -19,21 +18,11 @@ def process_video(video_file, api_key):
19
  base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
20
  video.release()
21
 
22
- # Instruction for narration generation
23
- INSTRUCTION = " ".join([
24
- "These are frames of a video.",
25
- "Create a short voiceover script in the style of a super excited Brazilian sports narrator who is narrating his favorite match.",
26
- "He is a big fan of Messi, the player who scores in this clip.",
27
- "Use caps and exclamation marks where needed to communicate excitement.",
28
- "Only include the narration, your output must be in English.",
29
- "When the ball goes into the net, you must scream GOL either once or multiple times."
30
- ])
31
-
32
  PROMPT_MESSAGES = [
33
  {
34
  "role": "user",
35
  "content": [
36
- INSTRUCTION,
37
  *map(lambda x: {"image": x, "resize": 768}, base64Frames[0::10]),
38
  ],
39
  },
@@ -44,7 +33,6 @@ def process_video(video_file, api_key):
44
  model="gpt-4-vision-preview",
45
  messages=PROMPT_MESSAGES,
46
  api_key=openai.api_key,
47
- headers={"Openai-Version": "2020-11-07"},
48
  max_tokens=500,
49
  )
50
  return result.choices[0].message.content
@@ -56,33 +44,17 @@ def main():
56
  with gr.Blocks() as app:
57
  gr.Markdown("## Video Narration Generator")
58
  with gr.Row():
59
- with gr.Column():
60
- api_key_input = gr.Textbox(label="Enter your OpenAI API Key")
61
- video_upload = gr.File(label="Upload your video")
62
- submit_button = gr.Button("Generate Script", elem_id="submit_button")
63
- with gr.Column():
64
- output_box = gr.Textbox(label="Generated Script", lines=10, interactive=False)
 
65
 
66
- submit_button.click(fn=process_video, inputs=[video_upload, api_key_input], outputs=output_box)
67
 
68
  app.launch()
69
 
70
  if __name__ == "__main__":
71
- main()
72
-
73
- # # Define the Gradio app
74
- # def main():
75
- # with gr.Blocks() as app:
76
- # gr.Markdown("## Video Narration Generator")
77
- # with gr.Row():
78
- # video_upload = gr.File(label="Upload your video")
79
- # api_key_input = gr.Textbox(label="Enter your OpenAI API Key")
80
- # submit_button = gr.Button("Generate Script")
81
- # output_box = gr.Textbox(label="Generated Script", lines=10, interactive=False)
82
-
83
- # submit_button.click(fn=process_video, inputs=[video_upload, api_key_input], outputs=output_box)
84
-
85
- # app.launch()
86
-
87
- # if __name__ == "__main__":
88
- # main()
 
2
  import cv2
3
  import base64
4
  import openai
 
5
 
6
+ def process_video(video_file, api_key, instruction):
7
  # Set the OpenAI API key
8
  openai.api_key = api_key
9
 
 
18
  base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
19
  video.release()
20
 
 
 
 
 
 
 
 
 
 
 
21
  PROMPT_MESSAGES = [
22
  {
23
  "role": "user",
24
  "content": [
25
+ instruction,
26
  *map(lambda x: {"image": x, "resize": 768}, base64Frames[0::10]),
27
  ],
28
  },
 
33
  model="gpt-4-vision-preview",
34
  messages=PROMPT_MESSAGES,
35
  api_key=openai.api_key,
 
36
  max_tokens=500,
37
  )
38
  return result.choices[0].message.content
 
44
  with gr.Blocks() as app:
45
  gr.Markdown("## Video Narration Generator")
46
  with gr.Row():
47
+ with gr.Column(scale=1):
48
+ api_key_input = gr.Textbox(label="Enter your OpenAI API Key", lines=1)
49
+ instruction_input = gr.Textbox(label="Enter Narration Instruction", placeholder="Enter your custom instruction here...", lines=5)
50
+ video_upload = gr.File(label="Upload your video", type="file")
51
+ submit_button = gr.Button("Generate Script")
52
+ with gr.Column(scale=1):
53
+ output_box = gr.Textbox(label="Generated Script", lines=7, interactive=False)
54
 
55
+ submit_button.click(fn=process_video, inputs=[video_upload, api_key_input, instruction_input], outputs=output_box)
56
 
57
  app.launch()
58
 
59
  if __name__ == "__main__":
60
+ main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/temp_video.mp4 ADDED
File without changes