jschwab21 commited on
Commit
4ba7330
·
verified ·
1 Parent(s): 90b9bf8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -52,13 +52,12 @@ custom_theme = CustomTheme()
52
  def save_uploaded_file(uploaded_file):
53
  if uploaded_file is None:
54
  return None # Handle cases where no file was uploaded
55
-
56
- filename, filedata = uploaded_file # Unpack the tuple into filename and binary data
57
  upload_dir = "uploaded_videos"
58
- os.makedirs(upload_dir, exist_ok=True) # Ensure the directory exists
59
- file_path = os.path.join(upload_dir, filename)
60
 
61
- # Write the binary data to a new file in the specified directory
62
  with open(file_path, "wb") as f:
63
  f.write(filedata)
64
  f.flush()
@@ -67,23 +66,18 @@ def save_uploaded_file(uploaded_file):
67
  print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes")
68
  return file_path
69
 
70
- # Define a function to process the video and display results
71
- def display_results(video_url, video_file, description):
72
- if video_url:
73
- # Process video from URL
74
- final_clip_path = process_video(video_url, description, is_url=True)
75
- elif video_file:
76
- # Save and process video from file upload
77
  video_file_path = save_uploaded_file(video_file)
78
  if video_file_path:
79
  final_clip_path = process_video(video_file_path, description, is_url=False)
 
80
  else:
81
- return "No file provided or file save error", None
82
  else:
83
- return "No input provided", None
84
-
85
- return final_clip_path, gr.Video.update(value=final_clip_path)
86
 
 
87
  css = """
88
  body {
89
  background-color: #ffffff;
@@ -135,8 +129,7 @@ h3 {
135
 
136
  with gr.Blocks() as demo:
137
  with gr.Column():
138
- video_url = gr.Textbox(label="Video URL")
139
- video_file = gr.File(label="Upload Video File", type="binary")
140
  description = gr.Textbox(label="Describe your clip")
141
  submit_button = gr.Button("Process Video")
142
  video_output = gr.Video(label="Processed Video")
@@ -144,7 +137,7 @@ with gr.Blocks() as demo:
144
 
145
  submit_button.click(
146
  fn=display_results,
147
- inputs=[video_url, video_file, description],
148
  outputs=[video_output, download_output]
149
  )
150
 
 
52
  def save_uploaded_file(uploaded_file):
53
  if uploaded_file is None:
54
  return None # Handle cases where no file was uploaded
55
+
56
+ filedata = uploaded_file # When using 'bytes', the filedata will be directly accessible
57
  upload_dir = "uploaded_videos"
58
+ os.makedirs(upload_dir, exist_ok=True)
59
+ file_path = os.path.join(upload_dir, "uploaded_video.mp4") # Using a fixed name for simplicity
60
 
 
61
  with open(file_path, "wb") as f:
62
  f.write(filedata)
63
  f.flush()
 
66
  print(f"File saved to {file_path}, size: {os.path.getsize(file_path)} bytes")
67
  return file_path
68
 
69
+ def display_results(video_file, description):
70
+ if video_file:
 
 
 
 
 
71
  video_file_path = save_uploaded_file(video_file)
72
  if video_file_path:
73
  final_clip_path = process_video(video_file_path, description, is_url=False)
74
+ return final_clip_path, gr.Video.update(value=final_clip_path)
75
  else:
76
+ return "File save error", None
77
  else:
78
+ return "No file provided", None
 
 
79
 
80
+
81
  css = """
82
  body {
83
  background-color: #ffffff;
 
129
 
130
  with gr.Blocks() as demo:
131
  with gr.Column():
132
+ upload_button = gr.UploadButton(label="Upload Video File", type="bytes", file_types=["video"])
 
133
  description = gr.Textbox(label="Describe your clip")
134
  submit_button = gr.Button("Process Video")
135
  video_output = gr.Video(label="Processed Video")
 
137
 
138
  submit_button.click(
139
  fn=display_results,
140
+ inputs=[upload_button, description],
141
  outputs=[video_output, download_output]
142
  )
143