Spaces:
Sleeping
Sleeping
Update app.py
Browse filestry another approach
app.py
CHANGED
@@ -47,16 +47,30 @@ image_sources = load_image_sources()
|
|
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 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
async def capture_screenshot(image_type: str):
|
61 |
"""Launches Playwright and uses user input, if any, to captures a screenshot of an image from p5.js."""
|
62 |
print("Launching Playwright...")
|
|
|
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].get(image_type, None)
|
57 |
+
# else:
|
58 |
+
# return None # No good match found
|
59 |
|
60 |
+
def get_image_url(image_type: str):
|
61 |
+
"""Finds an approximate match using simple substring matching."""
|
62 |
+
image_type = image_type.lower()
|
63 |
+
|
64 |
+
# Check for exact match first
|
65 |
+
if image_type in image_sources:
|
66 |
+
return image_sources[image_type]
|
67 |
+
|
68 |
+
# If no exact match, look for a partial match
|
69 |
+
for key in image_sources:
|
70 |
+
if image_type in key.lower(): # Check if input is a substring of a key
|
71 |
+
return image_sources[key]
|
72 |
+
|
73 |
+
return None # No match found
|
74 |
async def capture_screenshot(image_type: str):
|
75 |
"""Launches Playwright and uses user input, if any, to captures a screenshot of an image from p5.js."""
|
76 |
print("Launching Playwright...")
|