Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import time
|
|
7 |
import random
|
8 |
import gradio as gr
|
9 |
import shutil
|
|
|
|
|
10 |
|
11 |
# Các hàm phụ trợ giữ nguyên
|
12 |
def get_google_suggestions(query):
|
@@ -26,7 +28,7 @@ def download_images(search_term, num_images_per_term, save_folder, status_callba
|
|
26 |
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
|
27 |
|
28 |
try:
|
29 |
-
response = requests.get(
|
30 |
response.raise_for_status()
|
31 |
except:
|
32 |
status_callback(f"Lỗi truy cập {search_term}")
|
@@ -105,54 +107,80 @@ def start_download(initial_query, target_images, max_per_term, save_folder, zip_
|
|
105 |
|
106 |
return "\n".join(status_log), zip_file_path
|
107 |
|
108 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
def create_interface():
|
110 |
css = """
|
|
|
|
|
|
|
|
|
111 |
.container {
|
112 |
max-width: 1000px;
|
113 |
-
margin:
|
114 |
-
background: #
|
115 |
-
padding:
|
116 |
-
border-radius:
|
117 |
-
box-shadow: 0
|
118 |
}
|
119 |
h1 {
|
120 |
-
color: #
|
121 |
text-align: center;
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
123 |
margin-bottom: 20px;
|
124 |
}
|
125 |
.input-group {
|
126 |
-
background: #
|
127 |
padding: 15px;
|
128 |
-
border-radius:
|
129 |
margin-bottom: 15px;
|
130 |
}
|
131 |
.status-box {
|
132 |
-
background: #
|
133 |
-
border: 1px solid #
|
134 |
-
border-radius:
|
135 |
padding: 15px;
|
136 |
height: 350px;
|
|
|
137 |
font-family: 'Courier New', monospace;
|
138 |
font-size: 14px;
|
139 |
}
|
140 |
.button-primary {
|
141 |
-
background: #
|
142 |
color: white !important;
|
143 |
border: none !important;
|
144 |
-
border-radius:
|
145 |
-
padding:
|
146 |
font-weight: bold !important;
|
147 |
transition: all 0.3s !important;
|
148 |
}
|
149 |
.button-primary:hover {
|
150 |
-
background: #
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
}
|
153 |
.footer {
|
154 |
text-align: center;
|
155 |
-
color: #
|
156 |
font-size: 12px;
|
157 |
margin-top: 20px;
|
158 |
}
|
@@ -160,7 +188,7 @@ def create_interface():
|
|
160 |
|
161 |
with gr.Blocks(css=css, title="Image Downloader Pro") as demo:
|
162 |
gr.Markdown("<h1>📷 Image Downloader Pro</h1>")
|
163 |
-
gr.Markdown("<p
|
164 |
|
165 |
with gr.Row(elem_classes="container"):
|
166 |
with gr.Column(scale=1, min_width=300):
|
@@ -190,7 +218,7 @@ def create_interface():
|
|
190 |
value=os.path.join(os.getcwd(), "free_images"),
|
191 |
placeholder="Đường dẫn thư mục..."
|
192 |
)
|
193 |
-
folder_button = gr.Button("Chọn thư mục",
|
194 |
zip_files = gr.Checkbox(label="Nén thành ZIP sau khi tải", value=True)
|
195 |
submit_btn = gr.Button("Bắt đầu tải", elem_classes="button-primary")
|
196 |
|
@@ -208,12 +236,9 @@ def create_interface():
|
|
208 |
gr.Markdown("<p class='footer'>Powered by Gradio & xAI</p>")
|
209 |
|
210 |
# Xử lý chọn thư mục
|
211 |
-
def update_folder_path():
|
212 |
-
folder = gr.FileExplorer(glob="*/", root_dir=os.getcwd())
|
213 |
-
return folder
|
214 |
-
|
215 |
folder_button.click(
|
216 |
-
fn=
|
|
|
217 |
outputs=save_folder
|
218 |
)
|
219 |
|
|
|
7 |
import random
|
8 |
import gradio as gr
|
9 |
import shutil
|
10 |
+
import tkinter as tk
|
11 |
+
from tkinter import filedialog
|
12 |
|
13 |
# Các hàm phụ trợ giữ nguyên
|
14 |
def get_google_suggestions(query):
|
|
|
28 |
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"}
|
29 |
|
30 |
try:
|
31 |
+
response = requests.get(url, headers=headers, timeout=10)
|
32 |
response.raise_for_status()
|
33 |
except:
|
34 |
status_callback(f"Lỗi truy cập {search_term}")
|
|
|
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() # Ẩn cửa sổ chính của tkinter
|
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")
|
117 |
+
|
118 |
+
# Giao diện Gradio
|
119 |
def create_interface():
|
120 |
css = """
|
121 |
+
body {
|
122 |
+
background: #2b2b2b;
|
123 |
+
font-family: 'Segoe UI', sans-serif;
|
124 |
+
}
|
125 |
.container {
|
126 |
max-width: 1000px;
|
127 |
+
margin: 20px auto;
|
128 |
+
background: #36393f;
|
129 |
+
padding: 25px;
|
130 |
+
border-radius: 10px;
|
131 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
|
132 |
}
|
133 |
h1 {
|
134 |
+
color: #7289da;
|
135 |
text-align: center;
|
136 |
+
margin-bottom: 15px;
|
137 |
+
}
|
138 |
+
.description {
|
139 |
+
color: #b9bbbe;
|
140 |
+
text-align: center;
|
141 |
+
font-size: 14px;
|
142 |
margin-bottom: 20px;
|
143 |
}
|
144 |
.input-group {
|
145 |
+
background: #40444b;
|
146 |
padding: 15px;
|
147 |
+
border-radius: 8px;
|
148 |
margin-bottom: 15px;
|
149 |
}
|
150 |
.status-box {
|
151 |
+
background: #2f3136;
|
152 |
+
border: 1px solid #202225;
|
153 |
+
border-radius: 8px;
|
154 |
padding: 15px;
|
155 |
height: 350px;
|
156 |
+
color: #dcddde;
|
157 |
font-family: 'Courier New', monospace;
|
158 |
font-size: 14px;
|
159 |
}
|
160 |
.button-primary {
|
161 |
+
background: #7289da !important;
|
162 |
color: white !important;
|
163 |
border: none !important;
|
164 |
+
border-radius: 5px !important;
|
165 |
+
padding: 10px 20px !important;
|
166 |
font-weight: bold !important;
|
167 |
transition: all 0.3s !important;
|
168 |
}
|
169 |
.button-primary:hover {
|
170 |
+
background: #677bc4 !important;
|
171 |
+
}
|
172 |
+
.button-secondary {
|
173 |
+
background: #4f545c !important;
|
174 |
+
color: #dcddde !important;
|
175 |
+
border-radius: 5px !important;
|
176 |
+
padding: 8px 15px !important;
|
177 |
+
}
|
178 |
+
.button-secondary:hover {
|
179 |
+
background: #5c6169 !important;
|
180 |
}
|
181 |
.footer {
|
182 |
text-align: center;
|
183 |
+
color: #72767d;
|
184 |
font-size: 12px;
|
185 |
margin-top: 20px;
|
186 |
}
|
|
|
188 |
|
189 |
with gr.Blocks(css=css, title="Image Downloader Pro") as demo:
|
190 |
gr.Markdown("<h1>📷 Image Downloader Pro</h1>")
|
191 |
+
gr.Markdown("<p class='description'>Tải ảnh từ Google Images với giao diện tối giản và thân thiện</p>")
|
192 |
|
193 |
with gr.Row(elem_classes="container"):
|
194 |
with gr.Column(scale=1, min_width=300):
|
|
|
218 |
value=os.path.join(os.getcwd(), "free_images"),
|
219 |
placeholder="Đường dẫn thư mục..."
|
220 |
)
|
221 |
+
folder_button = gr.Button("Chọn thư mục", elem_classes="button-secondary")
|
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 |
|
|
|
236 |
gr.Markdown("<p class='footer'>Powered by Gradio & xAI</p>")
|
237 |
|
238 |
# Xử lý chọn thư mục
|
|
|
|
|
|
|
|
|
239 |
folder_button.click(
|
240 |
+
fn=select_folder,
|
241 |
+
inputs=[],
|
242 |
outputs=save_folder
|
243 |
)
|
244 |
|