oppaiio commited on
Commit
f03121e
·
verified ·
1 Parent(s): 934e0ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -45,6 +45,17 @@ def download_bilibili_video(url, output_dir="outputs"):
45
  return video_path, "✅ Đã tải xong video"
46
  except Exception as e:
47
  return None, f"❌ Exception: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  def step1_download(url):
50
  path, status = download_bilibili_video(url)
@@ -82,10 +93,11 @@ with gr.Blocks() as demo:
82
  processed_video = gr.Video(label="📝 Video đã xử lý")
83
 
84
  status_output = gr.Textbox(label="📢 Trạng thái")
85
-
86
  # Sự kiện nút
87
  download_btn.click(fn=step1_download, inputs=url_input, outputs=[orig_video, processed_video, status_output])
88
  process_btn.click(fn=step2_process, inputs=url_input, outputs=[orig_video, processed_video, status_output])
 
89
 
90
  if __name__ == "__main__":
91
  demo.launch()
 
45
  return video_path, "✅ Đã tải xong video"
46
  except Exception as e:
47
  return None, f"❌ Exception: {str(e)}"
48
+ def clear_outputs_folder():
49
+ folder = "outputs"
50
+ count = 0
51
+ for f in os.listdir(folder):
52
+ try:
53
+ os.remove(os.path.join(folder, f))
54
+ count += 1
55
+ except Exception as e:
56
+ print(f"❌ Lỗi khi xóa file {f}: {e}")
57
+ downloaded_videos.clear()
58
+ return None, None, f"🧹 Đã xoá {count} file trong thư mục outputs/"
59
 
60
  def step1_download(url):
61
  path, status = download_bilibili_video(url)
 
93
  processed_video = gr.Video(label="📝 Video đã xử lý")
94
 
95
  status_output = gr.Textbox(label="📢 Trạng thái")
96
+ clear_btn = gr.Button("🧹 Xoá thư mục outputs")
97
  # Sự kiện nút
98
  download_btn.click(fn=step1_download, inputs=url_input, outputs=[orig_video, processed_video, status_output])
99
  process_btn.click(fn=step2_process, inputs=url_input, outputs=[orig_video, processed_video, status_output])
100
+ clear_btn.click(fn=clear_outputs_folder, inputs=[], outputs=[orig_video, processed_video, status_output])
101
 
102
  if __name__ == "__main__":
103
  demo.launch()