Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- README.md +29 -7
- app.py +200 -0
- requirements.txt +14 -0
README.md
CHANGED
|
@@ -1,14 +1,36 @@
|
|
| 1 |
---
|
| 2 |
-
title: Fooocus
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
-
short_description: Fooocus pro presents a rethinking of image generator designs
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Fooocus Web
|
| 3 |
+
emoji: 🎨
|
| 4 |
+
colorFrom: purple
|
| 5 |
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.19.2
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Fooocus Web
|
| 13 |
+
|
| 14 |
+
A web interface for Fooocus, the powerful Stable Diffusion image generation tool.
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
|
| 18 |
+
- High-quality image generation
|
| 19 |
+
- Advanced prompt processing
|
| 20 |
+
- Multiple styles and presets
|
| 21 |
+
- Negative prompts support
|
| 22 |
+
- Advanced sampling methods
|
| 23 |
+
- Refiner integration
|
| 24 |
+
|
| 25 |
+
## Usage
|
| 26 |
+
|
| 27 |
+
1. Enter your prompt in the text box
|
| 28 |
+
2. Adjust the settings as needed
|
| 29 |
+
3. Click "Generate" to create your image
|
| 30 |
+
4. Use advanced features for more control
|
| 31 |
+
|
| 32 |
+
## Parameters
|
| 33 |
+
|
| 34 |
+
- **Style**: Choose from various preset styles
|
| 35 |
+
- **Performance**: Balance between quality and speed
|
| 36 |
+
- **Advanced**: Fine-tune the generation process
|
app.py
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
|
| 5 |
+
from safetensors.torch import load_file
|
| 6 |
+
|
| 7 |
+
# Constants
|
| 8 |
+
MODEL_ID = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 9 |
+
REFINER_MODEL_ID = "stabilityai/stable-diffusion-xl-refiner-1.0"
|
| 10 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
+
DTYPE = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 12 |
+
|
| 13 |
+
class FooocusGenerator:
|
| 14 |
+
def __init__(self):
|
| 15 |
+
self.pipe = None
|
| 16 |
+
self.refiner = None
|
| 17 |
+
self.load_models()
|
| 18 |
+
|
| 19 |
+
def load_models(self):
|
| 20 |
+
# Load base model
|
| 21 |
+
scheduler = EulerDiscreteScheduler.from_pretrained(MODEL_ID, subfolder="scheduler")
|
| 22 |
+
self.pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 23 |
+
MODEL_ID,
|
| 24 |
+
scheduler=scheduler,
|
| 25 |
+
torch_dtype=DTYPE,
|
| 26 |
+
use_safetensors=True,
|
| 27 |
+
variant="fp16" if DEVICE == "cuda" else None
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
if DEVICE == "cuda":
|
| 31 |
+
self.pipe.enable_xformers_memory_efficient_attention()
|
| 32 |
+
self.pipe.to(DEVICE)
|
| 33 |
+
|
| 34 |
+
def generate_image(
|
| 35 |
+
self,
|
| 36 |
+
prompt,
|
| 37 |
+
negative_prompt,
|
| 38 |
+
style_selections,
|
| 39 |
+
performance_selection,
|
| 40 |
+
aspect_ratios_selection,
|
| 41 |
+
image_number,
|
| 42 |
+
image_seed,
|
| 43 |
+
sharpness,
|
| 44 |
+
guidance_scale,
|
| 45 |
+
base_model_name,
|
| 46 |
+
refiner_model_name,
|
| 47 |
+
progress=gr.Progress()
|
| 48 |
+
):
|
| 49 |
+
try:
|
| 50 |
+
# Process style selections
|
| 51 |
+
processed_prompt = self.process_style(prompt, style_selections)
|
| 52 |
+
|
| 53 |
+
# Generate the image
|
| 54 |
+
generator = torch.Generator(device=DEVICE).manual_seed(image_seed)
|
| 55 |
+
|
| 56 |
+
image = self.pipe(
|
| 57 |
+
prompt=processed_prompt,
|
| 58 |
+
negative_prompt=negative_prompt,
|
| 59 |
+
num_inference_steps=30,
|
| 60 |
+
guidance_scale=guidance_scale,
|
| 61 |
+
generator=generator,
|
| 62 |
+
).images[0]
|
| 63 |
+
|
| 64 |
+
return image
|
| 65 |
+
|
| 66 |
+
except Exception as e:
|
| 67 |
+
print(f"Error generating image: {str(e)}")
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
def process_style(self, prompt, style_selections):
|
| 71 |
+
# Add style modifiers to the prompt
|
| 72 |
+
style_modifiers = {
|
| 73 |
+
"Fooocus V2": ", professional, high quality, detailed",
|
| 74 |
+
"Fooocus Enhance": ", enhanced details, perfect composition",
|
| 75 |
+
"Fooocus Sharp": ", sharp focus, high resolution",
|
| 76 |
+
"Fooocus Masterpiece": ", masterpiece, best quality, award winning",
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
selected_modifiers = [style_modifiers[style] for style in style_selections if style in style_modifiers]
|
| 80 |
+
processed_prompt = prompt + " ".join(selected_modifiers)
|
| 81 |
+
|
| 82 |
+
return processed_prompt
|
| 83 |
+
|
| 84 |
+
# Initialize the generator
|
| 85 |
+
generator = FooocusGenerator()
|
| 86 |
+
|
| 87 |
+
# Create the Gradio interface
|
| 88 |
+
with gr.Blocks(title="Fooocus Web", theme=gr.themes.Soft()) as demo:
|
| 89 |
+
gr.Markdown("# 🎨 Fooocus Web")
|
| 90 |
+
gr.Markdown("Generate high-quality images with advanced controls")
|
| 91 |
+
|
| 92 |
+
with gr.Row():
|
| 93 |
+
with gr.Column():
|
| 94 |
+
# Input components
|
| 95 |
+
prompt = gr.Textbox(
|
| 96 |
+
label="Prompt",
|
| 97 |
+
placeholder="Enter your image description here...",
|
| 98 |
+
info="Be specific and descriptive for better results"
|
| 99 |
+
)
|
| 100 |
+
negative_prompt = gr.Textbox(
|
| 101 |
+
label="Negative Prompt",
|
| 102 |
+
placeholder="What you don't want in the image...",
|
| 103 |
+
info="Specify unwanted elements",
|
| 104 |
+
value="ugly, blurry, low quality, distorted, deformed"
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
with gr.Row():
|
| 108 |
+
style_selections = gr.CheckboxGroup(
|
| 109 |
+
choices=["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp", "Fooocus Masterpiece"],
|
| 110 |
+
label="Style Selections",
|
| 111 |
+
value=["Fooocus V2"]
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
with gr.Row():
|
| 115 |
+
performance_selection = gr.Radio(
|
| 116 |
+
choices=["Speed", "Quality", "Extreme Speed"],
|
| 117 |
+
label="Performance",
|
| 118 |
+
value="Quality"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
aspect_ratios_selection = gr.Radio(
|
| 122 |
+
choices=["Square", "Portrait", "Landscape"],
|
| 123 |
+
label="Aspect Ratio",
|
| 124 |
+
value="Square"
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
with gr.Row():
|
| 128 |
+
image_number = gr.Slider(
|
| 129 |
+
minimum=1,
|
| 130 |
+
maximum=32,
|
| 131 |
+
value=1,
|
| 132 |
+
step=1,
|
| 133 |
+
label="Number of Images"
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
image_seed = gr.Slider(
|
| 137 |
+
minimum=-1,
|
| 138 |
+
maximum=2147483647,
|
| 139 |
+
step=1,
|
| 140 |
+
value=-1,
|
| 141 |
+
label="Seed (-1 for random)"
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
with gr.Row():
|
| 145 |
+
sharpness = gr.Slider(
|
| 146 |
+
minimum=0.0,
|
| 147 |
+
maximum=30.0,
|
| 148 |
+
value=2.0,
|
| 149 |
+
step=0.1,
|
| 150 |
+
label="Sharpness"
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
guidance_scale = gr.Slider(
|
| 154 |
+
minimum=1.0,
|
| 155 |
+
maximum=20.0,
|
| 156 |
+
value=7.5,
|
| 157 |
+
step=0.1,
|
| 158 |
+
label="Guidance Scale"
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
with gr.Row():
|
| 162 |
+
base_model_name = gr.Dropdown(
|
| 163 |
+
choices=["SDXL 1.0"],
|
| 164 |
+
label="Base Model",
|
| 165 |
+
value="SDXL 1.0"
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
refiner_model_name = gr.Dropdown(
|
| 169 |
+
choices=["SDXL Refiner"],
|
| 170 |
+
label="Refiner",
|
| 171 |
+
value="SDXL Refiner"
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
generate_btn = gr.Button("🎨 Generate", variant="primary")
|
| 175 |
+
|
| 176 |
+
with gr.Column():
|
| 177 |
+
# Output components
|
| 178 |
+
output_image = gr.Image(label="Generated Image", type="pil")
|
| 179 |
+
|
| 180 |
+
# Connect the interface
|
| 181 |
+
generate_btn.click(
|
| 182 |
+
fn=generator.generate_image,
|
| 183 |
+
inputs=[
|
| 184 |
+
prompt,
|
| 185 |
+
negative_prompt,
|
| 186 |
+
style_selections,
|
| 187 |
+
performance_selection,
|
| 188 |
+
aspect_ratios_selection,
|
| 189 |
+
image_number,
|
| 190 |
+
image_seed,
|
| 191 |
+
sharpness,
|
| 192 |
+
guidance_scale,
|
| 193 |
+
base_model_name,
|
| 194 |
+
refiner_model_name
|
| 195 |
+
],
|
| 196 |
+
outputs=output_image
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
if __name__ == "__main__":
|
| 200 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.2.1
|
| 2 |
+
transformers>=4.36.2
|
| 3 |
+
accelerate==0.25.0
|
| 4 |
+
safetensors==0.4.1
|
| 5 |
+
gradio==4.19.2
|
| 6 |
+
diffusers==0.24.0
|
| 7 |
+
opencv-python>=4.8.1.78
|
| 8 |
+
einops>=0.7.0
|
| 9 |
+
pytorch_lightning>=2.1.3
|
| 10 |
+
omegaconf>=2.3.0
|
| 11 |
+
peft>=0.7.1
|
| 12 |
+
xformers>=0.0.23.post1
|
| 13 |
+
triton>=2.1.0
|
| 14 |
+
compel>=2.0.2
|