25
25
display:block;
26
26
}
27
27
"""
28
+ tmp_upload_folder = "/tmp/gradio/"
28
29
29
30
# create a FastAPI app
30
31
app = FastAPI ()
@@ -122,11 +123,14 @@ def http_bot(state, request: gr.Request):
122
123
video_file = metadata ["source_video" ]
123
124
state .video_file = os .path .join (static_dir , metadata ["source_video" ])
124
125
state .time_of_frame_ms = metadata ["time_of_frame_ms" ]
125
- splited_video_path = split_video (
126
- state .video_file , state .time_of_frame_ms , tmp_dir , f"{ state .time_of_frame_ms } __{ video_file } "
127
- )
126
+ try :
127
+ splited_video_path = split_video (
128
+ state .video_file , state .time_of_frame_ms , tmp_dir , f"{ state .time_of_frame_ms } __{ video_file } "
129
+ )
130
+ except :
131
+ print (f"video { state .video_file } does not exist in UI host!" )
132
+ splited_video_path = None
128
133
state .split_video = splited_video_path
129
- print (splited_video_path )
130
134
else :
131
135
raise requests .exceptions .RequestException
132
136
except requests .exceptions .RequestException as e :
@@ -143,9 +147,19 @@ def http_bot(state, request: gr.Request):
143
147
144
148
def ingest_video_gen_transcript (filepath , request : gr .Request ):
145
149
yield (gr .Textbox (visible = True , value = "Please wait for ingesting your uploaded video into database..." ))
146
- basename = os .path .basename (filepath )
150
+ verified_filepath = os .path .normpath (filepath )
151
+ if not verified_filepath .startswith (tmp_upload_folder ):
152
+ print ("Found malicious video file name!" )
153
+ yield (
154
+ gr .Textbox (
155
+ visible = True ,
156
+ value = "Your uploaded video's file name has special characters that are not allowed. Please consider update the video file name!" ,
157
+ )
158
+ )
159
+ return
160
+ basename = os .path .basename (verified_filepath )
147
161
dest = os .path .join (static_dir , basename )
148
- shutil .copy (filepath , dest )
162
+ shutil .copy (verified_filepath , dest )
149
163
print ("Done copy uploaded file to static folder!" )
150
164
headers = {
151
165
# 'Content-Type': 'multipart/form-data'
@@ -185,9 +199,19 @@ def ingest_video_gen_transcript(filepath, request: gr.Request):
185
199
186
200
def ingest_video_gen_caption (filepath , request : gr .Request ):
187
201
yield (gr .Textbox (visible = True , value = "Please wait for ingesting your uploaded video into database..." ))
188
- basename = os .path .basename (filepath )
202
+ verified_filepath = os .path .normpath (filepath )
203
+ if not verified_filepath .startswith (tmp_upload_folder ):
204
+ print ("Found malicious video file name!" )
205
+ yield (
206
+ gr .Textbox (
207
+ visible = True ,
208
+ value = "Your uploaded video's file name has special characters that are not allowed. Please consider update the video file name!" ,
209
+ )
210
+ )
211
+ return
212
+ basename = os .path .basename (verified_filepath )
189
213
dest = os .path .join (static_dir , basename )
190
- shutil .copy (filepath , dest )
214
+ shutil .copy (verified_filepath , dest )
191
215
print ("Done copy uploaded file to static folder!" )
192
216
headers = {
193
217
# 'Content-Type': 'multipart/form-data'
0 commit comments