sdafd commited on
Commit
15d9a12
·
verified ·
1 Parent(s): d6a2d2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -194,16 +194,29 @@ def process_video(video, num_frames):
194
 
195
  nsfw_count = 0
196
  total_frames = len(frames)
 
197
 
198
  for frame_path in frames:
199
- if check_nsfw_final(f"https://sdafd-video-nsfw-detect.hf.space/file=/tmp/gradio/{frame_path}"):
 
 
 
 
 
200
  nsfw_count += 1
201
 
 
202
  for frame_path in frames:
203
- if os.path.exists(frame_path):
204
  os.remove('/tmp/gradio/' + frame_path)
205
 
206
- return f"{nsfw_count} out of {total_frames} frames were NSFW."
 
 
 
 
 
 
207
 
208
 
209
  with gr.Blocks() as app:
@@ -213,14 +226,14 @@ with gr.Blocks() as app:
213
  video_input = gr.Video(label="Upload Video")
214
  num_frames_input = gr.Number(label="Number of Frames to Check", value=10, precision=0)
215
 
216
- output_text = gr.Textbox(label="Result")
217
 
218
  submit_button = gr.Button("Submit")
219
 
220
  submit_button.click(
221
  fn=process_video,
222
  inputs=[video_input, num_frames_input],
223
- outputs=output_text
224
  )
225
 
226
  app.launch()
 
194
 
195
  nsfw_count = 0
196
  total_frames = len(frames)
197
+ frame_results = []
198
 
199
  for frame_path in frames:
200
+ nsfw_detected = check_nsfw_final(f"https://sdafd-video-nsfw-detect.hf.space/file=/tmp/gradio/{frame_path}")
201
+ frame_results.append({
202
+ "frame_path": frame_path,
203
+ "nsfw_detected": nsfw_detected
204
+ })
205
+ if nsfw_detected:
206
  nsfw_count += 1
207
 
208
+ # Cleanup
209
  for frame_path in frames:
210
+ if os.path.exists('/tmp/gradio/' + frame_path):
211
  os.remove('/tmp/gradio/' + frame_path)
212
 
213
+ result = {
214
+ "nsfw_count": nsfw_count,
215
+ "total_frames": total_frames,
216
+ "frames": frame_results
217
+ }
218
+
219
+ return result
220
 
221
 
222
  with gr.Blocks() as app:
 
226
  video_input = gr.Video(label="Upload Video")
227
  num_frames_input = gr.Number(label="Number of Frames to Check", value=10, precision=0)
228
 
229
+ output_json = gr.JSON(label="Result")
230
 
231
  submit_button = gr.Button("Submit")
232
 
233
  submit_button.click(
234
  fn=process_video,
235
  inputs=[video_input, num_frames_input],
236
+ outputs=output_json
237
  )
238
 
239
  app.launch()