jschwab21 commited on
Commit
51efef6
·
verified ·
1 Parent(s): 7dbced5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -49,27 +49,39 @@ class CustomTheme(Base):
49
 
50
  custom_theme = CustomTheme()
51
 
52
- def save_uploaded_file(file):
 
 
 
 
 
53
  upload_dir = "uploaded_videos"
54
  os.makedirs(upload_dir, exist_ok=True)
55
- file_path = os.path.join(upload_dir, file.name)
 
 
56
  with open(file_path, "wb") as f:
57
- # Use .read() to read the file content from the TemporaryUploadedFile
58
- f.write(file.file.read())
59
  return file_path
60
 
61
  def display_results(video_url, video_file, description):
 
 
 
62
  if video_url:
63
  final_clip_path = process_video(video_url, description, is_url=True)
64
  elif video_file:
65
  video_file_path = save_uploaded_file(video_file)
66
- final_clip_path = process_video(video_file_path, description, is_url=False)
67
- else:
68
- return "No video provided", None
 
69
 
70
  if final_clip_path:
71
  return final_clip_path, final_clip_path
72
- return "No matching scene found", None
 
73
 
74
  # Custom CSS for additional styling
75
  css = """
@@ -129,7 +141,6 @@ with gr.Blocks() as demo:
129
  submit_button = gr.Button("Process Video")
130
  video_output = gr.Video(label="Processed Video")
131
  download_output = gr.File(label="Download Processed Video")
132
-
133
  submit_button.click(
134
  fn=display_results,
135
  inputs=[video_url, video_file, description],
 
49
 
50
  custom_theme = CustomTheme()
51
 
52
+ def save_uploaded_file(uploaded_file):
53
+ """Save the uploaded file to disk."""
54
+ if uploaded_file is None:
55
+ return None # No file was uploaded
56
+
57
+ # Gradio uploads come with a .name attribute and file content is accessible via .read()
58
  upload_dir = "uploaded_videos"
59
  os.makedirs(upload_dir, exist_ok=True)
60
+ file_path = os.path.join(upload_dir, uploaded_file.name)
61
+
62
+ # Save the temporary file to a new location
63
  with open(file_path, "wb") as f:
64
+ f.write(uploaded_file.read()) # Read bytes from the uploaded file
65
+
66
  return file_path
67
 
68
  def display_results(video_url, video_file, description):
69
+ """Process video from URL or file upload and return the results."""
70
+ final_clip_path = None
71
+
72
  if video_url:
73
  final_clip_path = process_video(video_url, description, is_url=True)
74
  elif video_file:
75
  video_file_path = save_uploaded_file(video_file)
76
+ if video_file_path:
77
+ final_clip_path = process_video(video_file_path, description, is_url=False)
78
+ else:
79
+ return "No file provided or file save error", None
80
 
81
  if final_clip_path:
82
  return final_clip_path, final_clip_path
83
+ else:
84
+ return "No matching scene found", None
85
 
86
  # Custom CSS for additional styling
87
  css = """
 
141
  submit_button = gr.Button("Process Video")
142
  video_output = gr.Video(label="Processed Video")
143
  download_output = gr.File(label="Download Processed Video")
 
144
  submit_button.click(
145
  fn=display_results,
146
  inputs=[video_url, video_file, description],