Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
|
|
12 |
# Load the Unsplash dataset
|
13 |
dataset = load_dataset("jamescalam/unsplash-25k-photos", split="train") # all 25K images are in train split
|
14 |
|
15 |
-
height =
|
16 |
|
17 |
def predict(image, labels):
|
18 |
inputs = processor(text=[f"a photo of {c}" for c in labels], images=image, return_tensors="pt", padding=True)
|
@@ -24,7 +24,7 @@ def predict(image, labels):
|
|
24 |
def rand_image():
|
25 |
n = dataset.num_rows
|
26 |
r = random.randrange(0,n)
|
27 |
-
return dataset[r]["photo_image_url"]
|
28 |
|
29 |
def set_labels(text):
|
30 |
return text.split(",")
|
|
|
12 |
# Load the Unsplash dataset
|
13 |
dataset = load_dataset("jamescalam/unsplash-25k-photos", split="train") # all 25K images are in train split
|
14 |
|
15 |
+
height = 256 # height for resizing images
|
16 |
|
17 |
def predict(image, labels):
|
18 |
inputs = processor(text=[f"a photo of {c}" for c in labels], images=image, return_tensors="pt", padding=True)
|
|
|
24 |
def rand_image():
|
25 |
n = dataset.num_rows
|
26 |
r = random.randrange(0,n)
|
27 |
+
return dataset[r]["photo_image_url"] + f"?h={height}" # Unsplash allows dynamic requests, including size of image
|
28 |
|
29 |
def set_labels(text):
|
30 |
return text.split(",")
|