Spaces:
Running
on
Zero
Running
on
Zero
feat: Enable MCP
#1
by
multimodalart
HF Staff
- opened
app.py
CHANGED
@@ -105,7 +105,20 @@ def resize_and_crop_image(image):
|
|
105 |
return cropped_image, message, original_size
|
106 |
|
107 |
def handle_image_upload(image):
|
108 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
global original_image_size
|
110 |
|
111 |
if image is None:
|
@@ -132,7 +145,30 @@ def process_generated_image(
|
|
132 |
localization_model,
|
133 |
progress=gr.Progress(track_tqdm=True)
|
134 |
):
|
135 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
global pipe
|
137 |
|
138 |
if pipe is None:
|
@@ -199,7 +235,33 @@ def process_real_image(
|
|
199 |
disable_inversion,
|
200 |
progress=gr.Progress(track_tqdm=True)
|
201 |
):
|
202 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
global pipe
|
204 |
|
205 |
if pipe is None:
|
@@ -506,5 +568,6 @@ demo = create_interface()
|
|
506 |
demo.launch(
|
507 |
server_name="0.0.0.0",
|
508 |
server_port=7860,
|
509 |
-
share=True
|
510 |
-
|
|
|
|
105 |
return cropped_image, message, original_size
|
106 |
|
107 |
def handle_image_upload(image):
|
108 |
+
"""
|
109 |
+
Handle image upload and preprocessing for the Gradio interface.
|
110 |
+
|
111 |
+
This function is called when a user uploads an image to the real images tab.
|
112 |
+
It stores the original image size globally and processes the image to the required dimensions.
|
113 |
+
|
114 |
+
Args:
|
115 |
+
image: PIL.Image object uploaded by the user, or None if no image is uploaded.
|
116 |
+
|
117 |
+
Returns:
|
118 |
+
Tuple containing:
|
119 |
+
- processed_image: PIL.Image object resized and cropped to 1024x1024, or None if no image.
|
120 |
+
- message: HTML-formatted string indicating the processing status, or empty string.
|
121 |
+
"""
|
122 |
global original_image_size
|
123 |
|
124 |
if image is None:
|
|
|
145 |
localization_model,
|
146 |
progress=gr.Progress(track_tqdm=True)
|
147 |
):
|
148 |
+
"""
|
149 |
+
Process and generate images using ADDIT for the generated images workflow.
|
150 |
+
|
151 |
+
This function generates a source image from a text prompt and then adds an object to it
|
152 |
+
based on the target prompt and subject token using the ADDIT pipeline.
|
153 |
+
|
154 |
+
Args:
|
155 |
+
prompt_source: String describing the source scene without the object to be added.
|
156 |
+
prompt_target: String describing the target scene including the object to be added.
|
157 |
+
subject_token: String token representing the object to add (must appear in target prompt).
|
158 |
+
seed_src: Integer seed for generating the source image.
|
159 |
+
seed_obj: Integer seed for generating the object.
|
160 |
+
extended_scale: Float value (1.0-1.3) controlling the extended attention scale.
|
161 |
+
structure_transfer_step: Integer (0-10) controlling structure transfer strength.
|
162 |
+
blend_steps: String of comma-separated integers for blending steps, or empty string.
|
163 |
+
localization_model: String specifying the localization model to use.
|
164 |
+
progress: Gradio progress tracker for displaying progress updates.
|
165 |
+
|
166 |
+
Returns:
|
167 |
+
Tuple containing:
|
168 |
+
- src_image: PIL.Image of the generated source image, or None if error.
|
169 |
+
- edited_image: PIL.Image with the added object, or None if error.
|
170 |
+
- status_message: String describing the result or error message.
|
171 |
+
"""
|
172 |
global pipe
|
173 |
|
174 |
if pipe is None:
|
|
|
235 |
disable_inversion,
|
236 |
progress=gr.Progress(track_tqdm=True)
|
237 |
):
|
238 |
+
"""
|
239 |
+
Process and edit a real uploaded image using ADDIT to add objects.
|
240 |
+
|
241 |
+
This function takes an uploaded image and adds an object to it based on the target prompt
|
242 |
+
and subject token using the ADDIT pipeline with optional inversion and offset techniques.
|
243 |
+
|
244 |
+
Args:
|
245 |
+
source_image: PIL.Image object of the uploaded source image to edit.
|
246 |
+
prompt_source: String describing the source image content.
|
247 |
+
prompt_target: String describing the desired result including the object to add.
|
248 |
+
subject_token: String token representing the object to add (must appear in target prompt).
|
249 |
+
seed_src: Integer seed for source image processing.
|
250 |
+
seed_obj: Integer seed for object generation.
|
251 |
+
extended_scale: Float value (1.0-1.3) controlling the extended attention scale.
|
252 |
+
structure_transfer_step: Integer (0-10) controlling structure transfer strength.
|
253 |
+
blend_steps: String of comma-separated integers for blending steps, or empty string.
|
254 |
+
localization_model: String specifying the localization model to use.
|
255 |
+
use_offset: Boolean indicating whether to use offset technique.
|
256 |
+
disable_inversion: Boolean indicating whether to disable DDIM inversion.
|
257 |
+
progress: Gradio progress tracker for displaying progress updates.
|
258 |
+
|
259 |
+
Returns:
|
260 |
+
Tuple containing:
|
261 |
+
- src_image: PIL.Image of the processed source image, or None if error.
|
262 |
+
- edited_image: PIL.Image with the added object, or None if error.
|
263 |
+
- status_message: String describing the result or error message.
|
264 |
+
"""
|
265 |
global pipe
|
266 |
|
267 |
if pipe is None:
|
|
|
568 |
demo.launch(
|
569 |
server_name="0.0.0.0",
|
570 |
server_port=7860,
|
571 |
+
share=True,
|
572 |
+
mcp_server=True
|
573 |
+
)
|