Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -385,9 +385,26 @@ def infer(
|
|
| 385 |
pil_images.append(img)
|
| 386 |
print(f"Loaded image from URL: {url_list[0]}")
|
| 387 |
else:
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
if(len(url_list) > 1):
|
| 393 |
img = load_image_from_url(url_list[1])
|
|
|
|
| 385 |
pil_images.append(img)
|
| 386 |
print(f"Loaded image from URL: {url_list[0]}")
|
| 387 |
else:
|
| 388 |
+
imgPath = os.path.join(face_dir, url_list[0])
|
| 389 |
+
if os.path.exists(imgPath):
|
| 390 |
+
imgChar = Image.open(imgPath).convert("RGB")
|
| 391 |
+
pil_images.append(imgChar)
|
| 392 |
+
print(f"Loaded image from Local: {url_list[0]}")
|
| 393 |
+
else:
|
| 394 |
+
ll_files = os.listdir(face_dir)
|
| 395 |
+
# 3. Lọc ra các file ảnh (bạn có thể tùy chỉnh các phần mở rộng)
|
| 396 |
+
image_extensions = ('.jpg', '.jpeg', '.png', '.webp')
|
| 397 |
+
image_files = [f for f in all_files if f.lower().endswith(image_extensions)]
|
| 398 |
+
random_image_name = random.choice(image_files)
|
| 399 |
+
random_image_path = os.path.join(face_dir, random_image_name)
|
| 400 |
+
|
| 401 |
+
# 5. Tải ảnh và thêm vào pil_images
|
| 402 |
+
try:
|
| 403 |
+
pil_images.append(Image.open(random_image_path).convert("RGB"))
|
| 404 |
+
print(f"Loaded random default image: {random_image_name}")
|
| 405 |
+
except Exception as e:
|
| 406 |
+
# Xử lý nếu file được chọn không phải là ảnh hợp lệ hoặc lỗi tải
|
| 407 |
+
raise gr.Error(f"Error loading random image '{random_image_name}': {e}")
|
| 408 |
|
| 409 |
if(len(url_list) > 1):
|
| 410 |
img = load_image_from_url(url_list[1])
|