Spaces:
Running
on
Zero
Running
on
Zero
Create config.py
Browse files
config.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Configuration file for FLUX Prompt Optimizer
|
| 3 |
+
Clean, simple, and focused configuration
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import torch
|
| 8 |
+
from typing import Dict, Any
|
| 9 |
+
|
| 10 |
+
# Application Configuration
|
| 11 |
+
APP_CONFIG = {
|
| 12 |
+
"title": "🚀 FLUX Prompt Optimizer",
|
| 13 |
+
"description": "Advanced image analysis and Flux prompt optimization",
|
| 14 |
+
"version": "2.0.0",
|
| 15 |
+
"author": "Pariente AI Research"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Model Configuration
|
| 19 |
+
MODEL_CONFIG = {
|
| 20 |
+
# Primary analysis model - choose one
|
| 21 |
+
"primary_model": "florence2", # or "bagel"
|
| 22 |
+
|
| 23 |
+
# Florence-2 settings
|
| 24 |
+
"florence2": {
|
| 25 |
+
"model_id": "microsoft/Florence-2-base",
|
| 26 |
+
"torch_dtype": torch.float16,
|
| 27 |
+
"device_map": "auto",
|
| 28 |
+
"trust_remote_code": True,
|
| 29 |
+
"max_new_tokens": 1024
|
| 30 |
+
},
|
| 31 |
+
|
| 32 |
+
# Bagel-7B settings (via API)
|
| 33 |
+
"bagel": {
|
| 34 |
+
"api_url": "https://huggingface.co/spaces/Malaji71/Bagel-7B-Demo",
|
| 35 |
+
"timeout": 30,
|
| 36 |
+
"max_retries": 3
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Device Configuration
|
| 41 |
+
def get_device_config() -> Dict[str, Any]:
|
| 42 |
+
"""Determine optimal device configuration"""
|
| 43 |
+
device_config = {
|
| 44 |
+
"device": "cpu",
|
| 45 |
+
"use_gpu": False,
|
| 46 |
+
"memory_efficient": True
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
if torch.cuda.is_available():
|
| 50 |
+
device_config.update({
|
| 51 |
+
"device": "cuda",
|
| 52 |
+
"use_gpu": True,
|
| 53 |
+
"gpu_memory_gb": torch.cuda.get_device_properties(0).total_memory / 1e9
|
| 54 |
+
})
|
| 55 |
+
elif hasattr(torch.backends, 'mps') and torch.backends.mps.is_available():
|
| 56 |
+
device_config.update({
|
| 57 |
+
"device": "mps",
|
| 58 |
+
"use_gpu": True
|
| 59 |
+
})
|
| 60 |
+
|
| 61 |
+
return device_config
|
| 62 |
+
|
| 63 |
+
# Processing Configuration
|
| 64 |
+
PROCESSING_CONFIG = {
|
| 65 |
+
"max_image_size": 1024,
|
| 66 |
+
"image_quality": 95,
|
| 67 |
+
"supported_formats": [".jpg", ".jpeg", ".png", ".webp"],
|
| 68 |
+
"batch_size": 1,
|
| 69 |
+
"timeout_seconds": 60
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
# Flux Prompt Rules
|
| 73 |
+
FLUX_RULES = {
|
| 74 |
+
"remove_patterns": [
|
| 75 |
+
r',\s*trending on artstation',
|
| 76 |
+
r',\s*trending on [^,]+',
|
| 77 |
+
r',\s*\d+k\s*',
|
| 78 |
+
r',\s*\d+k resolution',
|
| 79 |
+
r',\s*artstation',
|
| 80 |
+
r',\s*concept art',
|
| 81 |
+
r',\s*digital art',
|
| 82 |
+
r',\s*by greg rutkowski',
|
| 83 |
+
],
|
| 84 |
+
|
| 85 |
+
"camera_configs": {
|
| 86 |
+
"portrait": ", Shot on Hasselblad X2D 100C, 90mm f/2.5 lens at f/2.8, professional portrait photography",
|
| 87 |
+
"landscape": ", Shot on Phase One XT, 40mm f/4 lens at f/8, epic landscape photography",
|
| 88 |
+
"street": ", Shot on Leica M11, 35mm f/1.4 lens at f/2.8, documentary street photography",
|
| 89 |
+
"default": ", Shot on Phase One XF IQ4, 80mm f/2.8 lens at f/4, professional photography"
|
| 90 |
+
},
|
| 91 |
+
|
| 92 |
+
"lighting_enhancements": {
|
| 93 |
+
"dramatic": ", dramatic cinematic lighting",
|
| 94 |
+
"portrait": ", professional studio lighting with subtle rim light",
|
| 95 |
+
"default": ", masterful natural lighting"
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Scoring Configuration
|
| 100 |
+
SCORING_CONFIG = {
|
| 101 |
+
"max_score": 100,
|
| 102 |
+
"score_weights": {
|
| 103 |
+
"prompt_quality": 0.3,
|
| 104 |
+
"technical_details": 0.25,
|
| 105 |
+
"artistic_value": 0.25,
|
| 106 |
+
"flux_optimization": 0.2
|
| 107 |
+
},
|
| 108 |
+
|
| 109 |
+
"grade_thresholds": {
|
| 110 |
+
95: {"grade": "LEGENDARY", "color": "#059669"},
|
| 111 |
+
90: {"grade": "EXCELLENT", "color": "#10b981"},
|
| 112 |
+
80: {"grade": "VERY GOOD", "color": "#22c55e"},
|
| 113 |
+
70: {"grade": "GOOD", "color": "#f59e0b"},
|
| 114 |
+
60: {"grade": "FAIR", "color": "#f97316"},
|
| 115 |
+
0: {"grade": "NEEDS WORK", "color": "#ef4444"}
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
# Environment Configuration
|
| 120 |
+
ENVIRONMENT = {
|
| 121 |
+
"is_spaces": os.getenv("SPACE_ID") is not None,
|
| 122 |
+
"is_local": os.getenv("SPACE_ID") is None,
|
| 123 |
+
"log_level": os.getenv("LOG_LEVEL", "INFO"),
|
| 124 |
+
"debug_mode": os.getenv("DEBUG", "false").lower() == "true"
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
# Export main configurations
|
| 128 |
+
__all__ = [
|
| 129 |
+
"APP_CONFIG",
|
| 130 |
+
"MODEL_CONFIG",
|
| 131 |
+
"get_device_config",
|
| 132 |
+
"PROCESSING_CONFIG",
|
| 133 |
+
"FLUX_RULES",
|
| 134 |
+
"SCORING_CONFIG",
|
| 135 |
+
"ENVIRONMENT"
|
| 136 |
+
]
|