diff --git a/py/recipes/parsers/civitai_image.py b/py/recipes/parsers/civitai_image.py index 3b5ea42a..8024b473 100644 --- a/py/recipes/parsers/civitai_image.py +++ b/py/recipes/parsers/civitai_image.py @@ -153,10 +153,6 @@ class CivitaiApiMetadataParser(RecipeMetadataParser): # Process civitaiResources array if "civitaiResources" in metadata and isinstance(metadata["civitaiResources"], list): for resource in metadata["civitaiResources"]: - # Skip resources that aren't LoRAs or LyCORIS - if resource.get("type") not in ["lora", "lycoris"] and "type" not in resource: - continue - # Get unique identifier for deduplication version_id = str(resource.get("modelVersionId", "")) diff --git a/py/routes/recipe_routes.py b/py/routes/recipe_routes.py index cf1c67c2..44fcd8c8 100644 --- a/py/routes/recipe_routes.py +++ b/py/routes/recipe_routes.py @@ -22,7 +22,6 @@ from ..config import config # Check if running in standalone mode standalone_mode = 'nodes' not in sys.modules -from ..utils.utils import download_civitai_image from ..services.service_registry import ServiceRegistry # Add ServiceRegistry import # Only import MetadataRegistry in non-standalone mode @@ -376,16 +375,6 @@ class RecipeRoutes: # Use meta field from image_info as metadata if 'meta' in image_info: metadata = image_info['meta'] - - else: - # Not a Civitai image URL, use the original download method - temp_path = download_civitai_image(url) - - if not temp_path: - return web.json_response({ - "error": "Failed to download image from URL", - "loras": [] - }, status=400) # If metadata wasn't obtained from Civitai API, extract it from the image if metadata is None: @@ -638,21 +627,6 @@ class RecipeRoutes: image = base64.b64decode(image_base64) except Exception as e: return web.json_response({"error": f"Invalid base64 image data: {str(e)}"}, status=400) - elif image_url: - # Download image from URL - temp_path = download_civitai_image(image_url) - if not temp_path: - return web.json_response({"error": "Failed to download image from URL"}, status=400) - - # Read the downloaded image - with open(temp_path, 'rb') as f: - image = f.read() - - # Clean up temp file - try: - os.unlink(temp_path) - except: - pass else: return web.json_response({"error": "No image data provided"}, status=400) diff --git a/py/utils/utils.py b/py/utils/utils.py index 88adcb23..5acec3c9 100644 --- a/py/utils/utils.py +++ b/py/utils/utils.py @@ -1,8 +1,5 @@ from difflib import SequenceMatcher -import requests -import tempfile import os -from bs4 import BeautifulSoup from ..services.service_registry import ServiceRegistry from ..config import config import asyncio @@ -50,81 +47,6 @@ def get_lora_info(lora_name): # No event loop is running, we can use asyncio.run() return asyncio.run(_get_lora_info_async()) -def download_twitter_image(url): - """Download image from a URL containing twitter:image meta tag - - Args: - url (str): The URL to download image from - - Returns: - str: Path to downloaded temporary image file - """ - try: - # Download page content - response = requests.get(url) - response.raise_for_status() - - # Parse HTML - soup = BeautifulSoup(response.text, 'html.parser') - - # Find twitter:image meta tag - meta_tag = soup.find('meta', attrs={'property': 'twitter:image'}) - if not meta_tag: - return None - - image_url = meta_tag['content'] - - # Download image - image_response = requests.get(image_url) - image_response.raise_for_status() - - # Save to temp file - with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as temp_file: - temp_file.write(image_response.content) - return temp_file.name - - except Exception as e: - print(f"Error downloading twitter image: {e}") - return None - -def download_civitai_image(url): - """Download image from a URL containing avatar image with specific class and style attributes - - Args: - url (str): The URL to download image from - - Returns: - str: Path to downloaded temporary image file - """ - try: - # Download page content - response = requests.get(url) - response.raise_for_status() - - # Parse HTML - soup = BeautifulSoup(response.text, 'html.parser') - - # Find image with specific class and style attributes - image = soup.select_one('img.EdgeImage_image__iH4_q.max-h-full.w-auto.max-w-full') - - if not image or 'src' not in image.attrs: - return None - - image_url = image['src'] - - # Download image - image_response = requests.get(image_url) - image_response.raise_for_status() - - # Save to temp file - with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as temp_file: - temp_file.write(image_response.content) - return temp_file.name - - except Exception as e: - print(f"Error downloading civitai avatar: {e}") - return None - def fuzzy_match(text: str, pattern: str, threshold: float = 0.7) -> bool: """ Check if text matches pattern using fuzzy matching. diff --git a/pyproject.toml b/pyproject.toml index b7dba92c..65811333 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,11 +7,9 @@ dependencies = [ "aiohttp", "jinja2", "safetensors", - "beautifulsoup4", "piexif", "Pillow", "olefile", # for getting rid of warning message - "requests", "toml", "natsort", "GitPython" diff --git a/requirements.txt b/requirements.txt index 87c9f47f..05680486 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,9 @@ aiohttp jinja2 safetensors -beautifulsoup4 piexif Pillow olefile -requests toml numpy natsort