Spaces:
Running on Zero
Running on Zero
Maikeu Locatelli
Refactor app.py to implement HF Inference client for texture generation, enhancing model handling and error management. Update Gradio interface for improved user experience with advanced controls, presets, and history display. Modify settings for persistent storage in HF Spaces and adjust environment configuration for model ID. Add new dependencies in requirements.txt for huggingface_hub.
4bb998d | """Centralized configuration settings for the application.""" | |
| import os | |
| from pathlib import Path | |
| from typing import Optional | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| # Base paths | |
| BASE_DIR = Path(__file__).parent.parent | |
| # HF Spaces: use persistent storage when available (/data). Fallback to repo-local. | |
| _PERSISTENT_ROOT = Path("/data") | |
| _DEFAULT_OUTPUT_ROOT = _PERSISTENT_ROOT if _PERSISTENT_ROOT.exists() else BASE_DIR | |
| OUTPUT_DIR = _DEFAULT_OUTPUT_ROOT / os.getenv("OUTPUT_DIR", "generated_images") | |
| ASSETS_DIR = BASE_DIR / os.getenv("ASSETS_DIR", "assets") | |
| EXAMPLES_DIR = ASSETS_DIR / "examples" | |
| # Model configuration | |
| # For HF Inference / InferenceClient, prefer the canonical repo id (no "models/"). | |
| MODEL_ID = os.getenv("MODEL_ID", "gokaygokay/Flux-Seamless-Texture-LoRA") | |
| MODEL_PROVIDER = os.getenv("MODEL_PROVIDER", "hf-inference") | |
| # MCP configuration | |
| MCP_ENABLED = True | |
| MCP_ENDPOINT = "/gradio_api/mcp/" | |
| # Application settings | |
| MAX_IMAGES = int(os.getenv("MAX_IMAGES", "100")) | |
| CLEANUP_AFTER_DAYS = int(os.getenv("CLEANUP_AFTER_DAYS", "7")) | |
| ENABLE_WATERMARK = os.getenv("ENABLE_WATERMARK", "false").lower() == "true" | |
| # Logging | |
| LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO") | |
| LOG_FILE = os.getenv("LOG_FILE", "app.log") | |
| # Default generation parameters | |
| DEFAULT_PARAMS = { | |
| "guidance_scale": 7.5, | |
| "num_inference_steps": 50, | |
| "seed": None, | |
| "width": 1024, | |
| "height": 1024, | |
| "cfg_scale": 7.5, | |
| "negative_prompt": "", | |
| "lora_strength": 1.0, | |
| } | |
| # Create directories if they don't exist | |
| OUTPUT_DIR.mkdir(parents=True, exist_ok=True) | |
| ASSETS_DIR.mkdir(parents=True, exist_ok=True) | |
| EXAMPLES_DIR.mkdir(parents=True, exist_ok=True) | |