Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,28 +47,29 @@ image_sources = load_image_sources()
|
|
47 |
# def get_image_url(image_type: str):
|
48 |
# return image_sources.get(image_type, None)
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
#
|
|
|
59 |
|
60 |
-
def get_image_url(image_type: str):
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
return None # No match found
|
74 |
async def capture_screenshot(image_type: str):
|
|
|
47 |
# def get_image_url(image_type: str):
|
48 |
# return image_sources.get(image_type, None)
|
49 |
|
50 |
+
def get_image_url(image_type: str):
|
51 |
+
"""Finds the best match for the given image type using fuzzy matching."""
|
52 |
+
choices = list(image_sources.keys()) # Get all available keys
|
53 |
+
best_match, score = process.extractOne(image_type, choices) # Find closest match
|
54 |
|
55 |
+
if score > 70: # Set a threshold to ensure a reasonable match
|
56 |
+
return image_sources[best_match]
|
57 |
+
else:
|
58 |
+
#return None # No good match found
|
59 |
+
return "https://editor.p5js.org/kfahn/full/2XD5Y8MiV"
|
60 |
|
61 |
+
# def get_image_url(image_type: str):
|
62 |
+
# """Finds an approximate match using simple substring matching."""
|
63 |
+
# image_type = image_type.lower()
|
64 |
|
65 |
+
# # Check for exact match first
|
66 |
+
# if image_type in image_sources:
|
67 |
+
# return image_sources[image_type]
|
68 |
+
|
69 |
+
# # If no exact match, look for a partial match
|
70 |
+
# for key in image_sources:
|
71 |
+
# if image_type in key.lower(): # Check if input is a substring of a key
|
72 |
+
# return image_sources[key]
|
73 |
|
74 |
return None # No match found
|
75 |
async def capture_screenshot(image_type: str):
|