Spaces:
Running
on
Zero
Running
on
Zero
add docstrings explanation for MCP server mode
Browse files- gradio_ui.py +29 -1
gradio_ui.py
CHANGED
|
@@ -136,6 +136,34 @@ def process_image(image_path: str,
|
|
| 136 |
positive_prompt: Optional[str],
|
| 137 |
negative_prompt: Optional[str],
|
| 138 |
seed: int) -> tuple[PIL.Image.Image, str]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
torch.manual_seed(seed)
|
| 141 |
image = PIL.Image.open(image_path)
|
|
@@ -189,7 +217,7 @@ def create_interface():
|
|
| 189 |
|
| 190 |
def main():
|
| 191 |
interface = create_interface()
|
| 192 |
-
interface.launch(ssr_mode=False)
|
| 193 |
|
| 194 |
|
| 195 |
if __name__ == "__main__":
|
|
|
|
| 136 |
positive_prompt: Optional[str],
|
| 137 |
negative_prompt: Optional[str],
|
| 138 |
seed: int) -> tuple[PIL.Image.Image, str]:
|
| 139 |
+
|
| 140 |
+
"""Colorize a grayscale or low-color image using automatic captioning and text-guided diffusion.
|
| 141 |
+
|
| 142 |
+
This function performs image-to-image generation using a ControlNet model and Stable Diffusion XL,
|
| 143 |
+
guided by a text caption extracted from the image itself using a BLIP captioning model. Optional
|
| 144 |
+
prompts (positive and negative) can further influence the output style or content.
|
| 145 |
+
|
| 146 |
+
Process Overview:
|
| 147 |
+
1. The input image is loaded and resized to 512x512 for inference.
|
| 148 |
+
2. A BLIP model generates a caption describing the image content.
|
| 149 |
+
3. The caption is cleaned using a filtering function to remove misleading or unwanted terms.
|
| 150 |
+
4. A prompt is constructed by combining the user-provided positive prompt with the caption.
|
| 151 |
+
5. A ControlNet-guided image is generated using the SDXL pipeline.
|
| 152 |
+
6. The output image's color channels (A and B in LAB space) are applied to the original luminance (L)
|
| 153 |
+
of the control image to preserve structure while transferring color.
|
| 154 |
+
7. The image is resized back to the original resolution and returned.
|
| 155 |
+
|
| 156 |
+
Args:
|
| 157 |
+
image_path: Path to the grayscale or lightly colored input image (JPEG/PNG).
|
| 158 |
+
positive_prompt: Additional descriptive text to enhance or guide the generation.
|
| 159 |
+
negative_prompt: Words or phrases to avoid during generation (e.g., "blurry", "monochrome").
|
| 160 |
+
seed: Random seed for reproducible generation.
|
| 161 |
+
|
| 162 |
+
Returns:
|
| 163 |
+
A tuple containing:
|
| 164 |
+
- A colorized PIL image based on the input and generated caption.
|
| 165 |
+
- The cleaned caption string used to guide the generation.
|
| 166 |
+
"""
|
| 167 |
|
| 168 |
torch.manual_seed(seed)
|
| 169 |
image = PIL.Image.open(image_path)
|
|
|
|
| 217 |
|
| 218 |
def main():
|
| 219 |
interface = create_interface()
|
| 220 |
+
interface.launch(ssr_mode=False, mcp_server=True)
|
| 221 |
|
| 222 |
|
| 223 |
if __name__ == "__main__":
|