Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -107,10 +107,16 @@ def start_download(initial_query, target_images, max_per_term, save_folder, zip_
|
|
107 |
|
108 |
return "\n".join(status_log), zip_file_path
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
# Hàm chọn thư mục bằng tkinter
|
111 |
def select_folder():
|
112 |
root = tk.Tk()
|
113 |
-
root.withdraw()
|
114 |
folder = filedialog.askdirectory(initialdir=os.getcwd(), title="Chọn thư mục lưu")
|
115 |
root.destroy()
|
116 |
return folder if folder else os.path.join(os.getcwd(), "free_images")
|
@@ -184,6 +190,13 @@ def create_interface():
|
|
184 |
font-size: 12px;
|
185 |
margin-top: 20px;
|
186 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
"""
|
188 |
|
189 |
with gr.Blocks(css=css, title="Image Downloader Pro") as demo:
|
@@ -213,12 +226,21 @@ def create_interface():
|
|
213 |
value=20,
|
214 |
step=1
|
215 |
)
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
value=os.path.join(os.getcwd(), "free_images"),
|
219 |
-
|
220 |
)
|
221 |
-
|
|
|
|
|
222 |
zip_files = gr.Checkbox(label="Nén thành ZIP sau khi tải", value=True)
|
223 |
submit_btn = gr.Button("Bắt đầu tải", elem_classes="button-primary")
|
224 |
|
@@ -235,11 +257,23 @@ def create_interface():
|
|
235 |
|
236 |
gr.Markdown("<p class='footer'>Powered by Gradio & xAI</p>")
|
237 |
|
238 |
-
#
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
fn=select_folder,
|
241 |
inputs=[],
|
242 |
-
outputs=
|
243 |
)
|
244 |
|
245 |
# Xử lý tải
|
@@ -254,7 +288,7 @@ def create_interface():
|
|
254 |
|
255 |
submit_btn.click(
|
256 |
fn=run_download,
|
257 |
-
inputs=[initial_query, target_images, max_per_term,
|
258 |
outputs=[output_status, output_file]
|
259 |
)
|
260 |
|
|
|
107 |
|
108 |
return "\n".join(status_log), zip_file_path
|
109 |
|
110 |
+
# Hàm lấy danh sách thư mục con
|
111 |
+
def get_subfolders(root_dir):
|
112 |
+
if not os.path.exists(root_dir):
|
113 |
+
return [root_dir]
|
114 |
+
return [os.path.join(root_dir, d) for d in os.listdir(root_dir) if os.path.isdir(os.path.join(root_dir, d))]
|
115 |
+
|
116 |
# Hàm chọn thư mục bằng tkinter
|
117 |
def select_folder():
|
118 |
root = tk.Tk()
|
119 |
+
root.withdraw()
|
120 |
folder = filedialog.askdirectory(initialdir=os.getcwd(), title="Chọn thư mục lưu")
|
121 |
root.destroy()
|
122 |
return folder if folder else os.path.join(os.getcwd(), "free_images")
|
|
|
190 |
font-size: 12px;
|
191 |
margin-top: 20px;
|
192 |
}
|
193 |
+
.folder-explorer {
|
194 |
+
background: #2f3136;
|
195 |
+
padding: 10px;
|
196 |
+
border-radius: 5px;
|
197 |
+
max-height: 150px;
|
198 |
+
overflow-y: auto;
|
199 |
+
}
|
200 |
"""
|
201 |
|
202 |
with gr.Blocks(css=css, title="Image Downloader Pro") as demo:
|
|
|
226 |
value=20,
|
227 |
step=1
|
228 |
)
|
229 |
+
# Ô khám phá thư mục
|
230 |
+
root_folder = gr.Textbox(
|
231 |
+
label="Thư mục gốc",
|
232 |
+
value=os.getcwd(),
|
233 |
+
placeholder="Nhập thư mục gốc..."
|
234 |
+
)
|
235 |
+
folder_dropdown = gr.Dropdown(
|
236 |
+
label="Chọn thư mục con",
|
237 |
+
choices=get_subfolders(os.getcwd()),
|
238 |
value=os.path.join(os.getcwd(), "free_images"),
|
239 |
+
elem_classes="folder-explorer"
|
240 |
)
|
241 |
+
with gr.Row():
|
242 |
+
refresh_button = gr.Button("Làm mới", elem_classes="button-secondary")
|
243 |
+
tk_folder_button = gr.Button("Chọn bằng hộp thoại", elem_classes="button-secondary")
|
244 |
zip_files = gr.Checkbox(label="Nén thành ZIP sau khi tải", value=True)
|
245 |
submit_btn = gr.Button("Bắt đầu tải", elem_classes="button-primary")
|
246 |
|
|
|
257 |
|
258 |
gr.Markdown("<p class='footer'>Powered by Gradio & xAI</p>")
|
259 |
|
260 |
+
# Hàm cập nhật danh sách thư mục con
|
261 |
+
def update_folders(root_dir):
|
262 |
+
subfolders = get_subfolders(root_dir)
|
263 |
+
return gr.Dropdown.update(choices=subfolders, value=subfolders[0] if subfolders else root_dir)
|
264 |
+
|
265 |
+
# Sự kiện làm mới danh sách thư mục
|
266 |
+
refresh_button.click(
|
267 |
+
fn=update_folders,
|
268 |
+
inputs=root_folder,
|
269 |
+
outputs=folder_dropdown
|
270 |
+
)
|
271 |
+
|
272 |
+
# Sự kiện chọn thư mục bằng tkinter
|
273 |
+
tk_folder_button.click(
|
274 |
fn=select_folder,
|
275 |
inputs=[],
|
276 |
+
outputs=folder_dropdown
|
277 |
)
|
278 |
|
279 |
# Xử lý tải
|
|
|
288 |
|
289 |
submit_btn.click(
|
290 |
fn=run_download,
|
291 |
+
inputs=[initial_query, target_images, max_per_term, folder_dropdown, zip_files],
|
292 |
outputs=[output_status, output_file]
|
293 |
)
|
294 |
|