Spaces:
Sleeping
Sleeping
Commit ·
dc5bd85
1
Parent(s): 8ed59cf
Fixed issues
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import CLIPProcessor, CLIPModel
|
|
|
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
import os
|
|
@@ -48,11 +50,16 @@ def search_similar(image, text):
|
|
| 48 |
return paths, None
|
| 49 |
|
| 50 |
# Function to load images from paths
|
|
|
|
| 51 |
def load_images(paths):
|
| 52 |
images = []
|
| 53 |
for p in paths:
|
| 54 |
try:
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
images.append(img)
|
| 57 |
except Exception as e:
|
| 58 |
print(f"Failed to load {p}: {e}")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import CLIPProcessor, CLIPModel
|
| 3 |
+
import requests
|
| 4 |
+
from io import BytesIO
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
| 7 |
import os
|
|
|
|
| 50 |
return paths, None
|
| 51 |
|
| 52 |
# Function to load images from paths
|
| 53 |
+
|
| 54 |
def load_images(paths):
|
| 55 |
images = []
|
| 56 |
for p in paths:
|
| 57 |
try:
|
| 58 |
+
if p.startswith("http"):
|
| 59 |
+
response = requests.get(p)
|
| 60 |
+
img = Image.open(BytesIO(response.content)).convert("RGB")
|
| 61 |
+
else:
|
| 62 |
+
img = Image.open(p).convert("RGB")
|
| 63 |
images.append(img)
|
| 64 |
except Exception as e:
|
| 65 |
print(f"Failed to load {p}: {e}")
|