PierreBrunelle commited on
Commit
827c577
1 Parent(s): 29dacc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -43,10 +43,10 @@ def process_and_generate_post(video_file, social_media_type, progress=gr.Progres
43
  t['metadata'] = get_metadata(t.audio)
44
  t['transcription'] = openai.transcriptions(audio=t.audio, model='whisper-1')
45
  t['transcription_text'] = t.transcription.text
 
 
46
 
47
- # Custom UDF for Generating Social Media Prompts
48
-
49
- #Custom User-Defined Function (UDF) for Generating Social Media Prompts
50
  @pxt.udf
51
  def prompt(A: str, B: str) -> list[dict]:
52
  system_msg = 'You are an expert in creating social media content and you generate effective post, based on user content. Respect the social media platform guidelines and constraints.'
@@ -60,6 +60,8 @@ def process_and_generate_post(video_file, social_media_type, progress=gr.Progres
60
  t['message'] = prompt(t.sm_type, t.transcription_text)
61
 
62
  """## Generating Responses with OpenAI's GPT Model"""
 
 
63
 
64
  # # Generate responses using OpenAI's chat completion API
65
  t['response'] = openai.chat_completions(messages=t.message, model='gpt-4o-mini-2024-07-18', max_tokens=500)
@@ -77,24 +79,22 @@ def process_and_generate_post(video_file, social_media_type, progress=gr.Progres
77
  if video_size > MAX_VIDEO_SIZE_MB:
78
  return f"The video file is larger than {MAX_VIDEO_SIZE_MB} MB. Please upload a smaller file.", None
79
 
 
 
80
  # # Insert a video into the table. Pixeltable supports referencing external data sources like URLs
81
  t.insert([{
82
  "video": video_file,
83
  "sm_type": social_media_type
84
  }])
85
 
86
- progress(0.2, desc="Extracting audio and frames...")
87
-
88
  # Retrieve Social media posts
89
  social_media_post = t.select(t.answer).tail(1)['answer'][0]
90
 
91
- progress(0.4, desc="Transcribing audio...")
92
-
93
  # Retrieve Audio
94
  audio = t.select(t.audio).tail(1)['audio'][0]
95
 
96
- progress(0.6, desc="Generating posts...")
97
-
98
  # Retrieve thumbnails
99
  thumbnails = frames_view.select(frames_view.frame).tail(6)['frame']
100
 
@@ -162,8 +162,10 @@ def gradio_interface():
162
 
163
  gr.Examples(
164
  examples=[["example1.mp4"], ["example2.mp4"], ["example3.mp4"]],
165
- inputs=[video_input]
166
  )
 
 
167
  with gr.Column():
168
  output = gr.Textbox(label="Generated Social Media Post", show_copy_button=True)
169
  thumbnail = gr.Gallery(
@@ -172,7 +174,6 @@ def gradio_interface():
172
  show_fullscreen_button=True,
173
  height='400px'
174
  )
175
- audio = gr.Audio(label="Extracted audio", show_download_button=True)
176
 
177
  df_output = gr.Textbox(label="Transcription", show_copy_button=True)
178
 
 
43
  t['metadata'] = get_metadata(t.audio)
44
  t['transcription'] = openai.transcriptions(audio=t.audio, model='whisper-1')
45
  t['transcription_text'] = t.transcription.text
46
+
47
+ progress(0.1, desc="Creating UDFs...")
48
 
49
+ # Custom User-Defined Function (UDF) for Generating Social Media Prompts
 
 
50
  @pxt.udf
51
  def prompt(A: str, B: str) -> list[dict]:
52
  system_msg = 'You are an expert in creating social media content and you generate effective post, based on user content. Respect the social media platform guidelines and constraints.'
 
60
  t['message'] = prompt(t.sm_type, t.transcription_text)
61
 
62
  """## Generating Responses with OpenAI's GPT Model"""
63
+
64
+ progress(0.2, desc="Calling LLMs")
65
 
66
  # # Generate responses using OpenAI's chat completion API
67
  t['response'] = openai.chat_completions(messages=t.message, model='gpt-4o-mini-2024-07-18', max_tokens=500)
 
79
  if video_size > MAX_VIDEO_SIZE_MB:
80
  return f"The video file is larger than {MAX_VIDEO_SIZE_MB} MB. Please upload a smaller file.", None
81
 
82
+ progress(0.4, desc="Inserting video...")
83
+
84
  # # Insert a video into the table. Pixeltable supports referencing external data sources like URLs
85
  t.insert([{
86
  "video": video_file,
87
  "sm_type": social_media_type
88
  }])
89
 
90
+ progress(0.6, desc="Generating posts...")
91
+
92
  # Retrieve Social media posts
93
  social_media_post = t.select(t.answer).tail(1)['answer'][0]
94
 
 
 
95
  # Retrieve Audio
96
  audio = t.select(t.audio).tail(1)['audio'][0]
97
 
 
 
98
  # Retrieve thumbnails
99
  thumbnails = frames_view.select(frames_view.frame).tail(6)['frame']
100
 
 
162
 
163
  gr.Examples(
164
  examples=[["example1.mp4"], ["example2.mp4"], ["example3.mp4"]],
165
+ inputs=[video_input], cache_examples=True
166
  )
167
+ audio = gr.Audio(label="Extracted audio", show_download_button=True)
168
+
169
  with gr.Column():
170
  output = gr.Textbox(label="Generated Social Media Post", show_copy_button=True)
171
  thumbnail = gr.Gallery(
 
174
  show_fullscreen_button=True,
175
  height='400px'
176
  )
 
177
 
178
  df_output = gr.Textbox(label="Transcription", show_copy_button=True)
179