anycoder-263f6cac / utils.py
xphillyx's picture
Upload folder using huggingface_hub
a2a83e2 verified
"""
Utility functions for Image Creation Studio
"""
def validate_prompt(prompt: str) -> bool:
"""Validate that prompt is not empty"""
return bool(prompt and prompt.strip())
def format_lora_string(loras: list) -> str:
"""Format LoRA names for prompt"""
if not loras:
return ""
return ", ".join([f"<lora:{name}:1.0>" for name in loras])
def parse_seed(seed_input: str) -> int:
"""Parse seed input, returning -1 for random"""
if seed_input == "-1" or seed_input == "":
return -1
try:
return int(seed_input)
except ValueError:
return -1
def get_model_info(model_name: str) -> dict:
"""Get model information"""
models = {
"Stable Diffusion 1.5": {
"base": "SD 1.5",
"recommended_steps": 20-30,
"recommended_guidance": 7-8
},
"Stable Diffusion 2.1": {
"base": "SD 2.1",
"recommended_steps": 25-35,
"recommended_guidance": 7-8
},
"Stable Diffusion XL 1.0": {
"base": "SDXL",
"recommended_steps": 30-50,
"recommended_guidance": 6-8
},
}
return models.get(model_name, {})
def create_negative_prompt_template() -> str:
"""Create a default negative prompt"""
return "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry"
# Example prompts for various styles
EXAMPLE_PROMPTS = {
"photorealistic": "masterpiece, best quality, photorealistic, 8k, professional photography, detailed, natural lighting",
"anime": "anime style, illustration, colorful, vibrant, detailed background, anime art",
"digital_art": "digital painting, concept art, detailed, intricate, beautiful composition",
"3d_render": "3d render, c4d, blender, octane render, detailed, realistic lighting",
"oil_painting": "oil painting, painterly, artstation, detailed brushstrokes, classical art",
}
def get_example_prompt(style: str) -> str:
"""Get example prompt for a style"""
return EXAMPLE_PROMPTS.get(style, "")
This is a comprehensive Gradio 6 image creation application with:
## Features:
### 1. **Text to Image Generation**
- Multiple Stable Diffusion models (SD 1.5, SD 2.1, SDXL, etc.)
- Aspect ratio presets (Square, Portrait, Landscape, etc.)
- Adjustable steps, guidance scale, and seed
- Hi-Res Fix for upscaling
### 2. **Prompt Enhancement**
- Three enhancement levels: subtle, moderate, extreme
- Adds quality tags, lighting, and detail keywords
- Copy enhanced prompt to main input
### 3. **LoRA Integration (civitai.com)**
- Search LoRAs from civitai.com
- Browse by category (Style, Character, Concept, Detail)
- Select multiple LoRAs for generation
- View download counts and ratings
### 4. **Additional Tabs**
- **Image to Image**: Transform existing images
- **Inpainting**: Edit specific areas
- **Prompt Builder**: Interactive visual prompt creation
- **Settings**: API configuration and defaults
### 5. **UI Features**
- Custom theme with soft colors
- Accordions for organized settings
- Examples for quick testing
- "Built with anycoder" link in header