denizaybey commited on
Commit
8214b7d
·
1 Parent(s): bef288f

Update Modal function call to use professional_reception_function and simplify response handling

Browse files
Files changed (1) hide show
  1. app.py +4 -22
app.py CHANGED
@@ -129,7 +129,6 @@ def process_video(video_path, notes, email, company_name) -> str:
129
 
130
  try:
131
  # 1. Setup Modal app and volume
132
- moderation_app = modal.App("Content-Moderation")
133
  _ = os.environ.get('MODAL_TOKEN_ID') # Read to ensure environment readiness (kept for parity with process_audio)
134
  _ = os.environ.get('MODAL_TOKEN_SECRET')
135
  _ = os.environ.get('MODAL_ENVIRONMENT')
@@ -154,8 +153,8 @@ def process_video(video_path, notes, email, company_name) -> str:
154
 
155
  # 4. Call Modal function synchronously
156
  try:
157
- moderation_function = modal.Function.from_name("Content-Moderation", "reception_function")
158
- processed_remote_path = moderation_function.remote(
159
  input_text=str(notes) if notes is not None else "",
160
  video_path=remote_input_path,
161
  size=(int(width), int(height)),
@@ -166,25 +165,8 @@ def process_video(video_path, notes, email, company_name) -> str:
166
  logger.error(f"Error calling Modal reception_function: {e}")
167
  return "Error calling Outpost to trigger processing."
168
 
169
- if not processed_remote_path or not isinstance(processed_remote_path, str):
170
- logger.error("Modal function did not return a valid path to the processed video.")
171
- return "Processing failed to return an output path."
172
 
173
- # 5. Download the processed video to /tmp with UUID filename
174
- local_ext = os.path.splitext(processed_remote_path)[1] or ext or ".mp4"
175
- local_output_path = f"/tmp/{uuid.uuid4().hex}{local_ext}"
176
- try:
177
- # Use Modal Volume.read_file to stream the remote file to the local path
178
- with open(local_output_path, "wb") as dst:
179
- for chunk in volume.read_file(processed_remote_path):
180
- if chunk:
181
- dst.write(chunk)
182
- except Exception as e:
183
- logger.error(f"Error downloading processed video from Modal Storage using read_file: {e}")
184
- return "Error downloading processed video from Cloud Storage."
185
-
186
- # 6. Return local path
187
- return local_output_path
188
 
189
  except Exception as e:
190
  logger.error(f"Unexpected error in process_video: {e}")
@@ -445,7 +427,7 @@ with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="indigo", secondary_hue
445
 
446
  # Third Row: Single Video Output
447
  with gr.Row(elem_classes="output-section"):
448
- cm_video_out = gr.Video(label="Video Output")
449
 
450
  # Final Row: Process button
451
  with gr.Row():
 
129
 
130
  try:
131
  # 1. Setup Modal app and volume
 
132
  _ = os.environ.get('MODAL_TOKEN_ID') # Read to ensure environment readiness (kept for parity with process_audio)
133
  _ = os.environ.get('MODAL_TOKEN_SECRET')
134
  _ = os.environ.get('MODAL_ENVIRONMENT')
 
153
 
154
  # 4. Call Modal function synchronously
155
  try:
156
+ moderation_function = modal.Function.from_name("Content-Moderation", "professional_reception_function")
157
+ moderation_function.spawn(
158
  input_text=str(notes) if notes is not None else "",
159
  video_path=remote_input_path,
160
  size=(int(width), int(height)),
 
165
  logger.error(f"Error calling Modal reception_function: {e}")
166
  return "Error calling Outpost to trigger processing."
167
 
 
 
 
168
 
169
+ return "Video Request Obtained"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
  except Exception as e:
172
  logger.error(f"Unexpected error in process_video: {e}")
 
427
 
428
  # Third Row: Single Video Output
429
  with gr.Row(elem_classes="output-section"):
430
+ cm_video_out = gr.Textbox(label="Output")
431
 
432
  # Final Row: Process button
433
  with gr.Row():