Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadd fuzzy matching
app.py
CHANGED
|
@@ -10,6 +10,7 @@ from playwright.async_api import async_playwright
|
|
| 10 |
from PIL import Image
|
| 11 |
import subprocess
|
| 12 |
import json
|
|
|
|
| 13 |
import gradio as gr
|
| 14 |
|
| 15 |
from tools.final_answer import FinalAnswerTool
|
|
@@ -43,8 +44,18 @@ def load_image_sources():
|
|
| 43 |
|
| 44 |
image_sources = load_image_sources()
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
def get_image_url(image_type: str):
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
async def capture_screenshot(image_type: str):
|
| 50 |
"""Launches Playwright and uses user input, if any, to captures a screenshot of an image from p5.js."""
|
|
|
|
| 10 |
from PIL import Image
|
| 11 |
import subprocess
|
| 12 |
import json
|
| 13 |
+
from rapidfuzz import process
|
| 14 |
import gradio as gr
|
| 15 |
|
| 16 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 44 |
|
| 45 |
image_sources = load_image_sources()
|
| 46 |
|
| 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 |
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."""
|