Desarrollo33 commited on
Commit
3dfcc89
ยท
1 Parent(s): 4caf6af

Add GLM-Image Editor tab

Browse files
Files changed (2) hide show
  1. app.py +54 -0
  2. requirements.txt +1 -0
app.py CHANGED
@@ -227,6 +227,40 @@ def generate_3d_model(image: Image.Image, engine_choice: str = "Trellis (Texture
227
  debug_logs.append("๐Ÿ’€ All engines failed.")
228
  return None, None, "\n".join(debug_logs)
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  # --- UI ---
231
  with gr.Blocks(title="DCR Vehicle Studio", theme=gr.themes.Monochrome()) as demo:
232
  gr.Markdown("# ๐Ÿš— DCR Vehicle Studio")
@@ -256,6 +290,26 @@ with gr.Blocks(title="DCR Vehicle Studio", theme=gr.themes.Monochrome()) as demo
256
  outputs=[out_no_bg, out_with_bg, out_upscaled]
257
  )
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  with gr.Tab("๐ŸŽฎ 3D Generation"):
260
  gr.Markdown("### Generate 3D Model")
261
  gr.Markdown("Choose your engine. **Trellis** provides textures but is experimental. **Hunyuan** is geometry only.")
 
227
  debug_logs.append("๐Ÿ’€ All engines failed.")
228
  return None, None, "\n".join(debug_logs)
229
 
230
+ # --- GLM-IMAGE EDITING ---
231
+ def edit_image_with_glm(image: Image.Image, prompt: str, strength: float = 0.8) -> Image.Image:
232
+ """Edit image using zai-org/GLM-Image via HF Inference"""
233
+ from huggingface_hub import InferenceClient
234
+
235
+ if image is None:
236
+ raise gr.Error("Please upload an image first")
237
+ if not prompt:
238
+ raise gr.Error("Please enter a prompt")
239
+
240
+ # Initialize client (uses HF_TOKEN env var automatically in Space)
241
+ client = InferenceClient("zai-org/GLM-Image")
242
+
243
+ # Save temp image for API
244
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f:
245
+ image.save(f.name)
246
+ temp_path = f.name
247
+
248
+ try:
249
+ # GLM-Image specifically for Image-to-Image text editing
250
+ # We use the standard image_to_image task
251
+ output_image = client.image_to_image(
252
+ image=image,
253
+ prompt=prompt,
254
+ strength=strength,
255
+ guidance_scale=7.5
256
+ )
257
+ return output_image
258
+ except Exception as e:
259
+ raise gr.Error(f"GLM Generation Failed: {str(e)}")
260
+ finally:
261
+ if os.path.exists(temp_path):
262
+ os.unlink(temp_path)
263
+
264
  # --- UI ---
265
  with gr.Blocks(title="DCR Vehicle Studio", theme=gr.themes.Monochrome()) as demo:
266
  gr.Markdown("# ๐Ÿš— DCR Vehicle Studio")
 
290
  outputs=[out_no_bg, out_with_bg, out_upscaled]
291
  )
292
 
293
+ with gr.Tab("โœจ GLM Image Editor"):
294
+ gr.Markdown("### Experimental: Z.AI GLM-Image Editor")
295
+ gr.Markdown("Use `zai-org/GLM-Image` to modify your vehicle photos.")
296
+
297
+ with gr.Row():
298
+ with gr.Column():
299
+ glm_input = gr.Image(type="pil", label="Input Image")
300
+ glm_prompt = gr.Textbox(label="Editing Prompt", placeholder="e.g. Change the car color to red, add snow on the ground")
301
+ glm_strength = gr.Slider(minimum=0.1, maximum=1.0, value=0.8, label="Transformation Strength (0.1 = subtle, 1.0 = heavy)")
302
+ glm_btn = gr.Button("โœจ Re-Imagine", variant="primary")
303
+
304
+ with gr.Column():
305
+ glm_output = gr.Image(label="GLM Result")
306
+
307
+ glm_btn.click(
308
+ fn=edit_image_with_glm,
309
+ inputs=[glm_input, glm_prompt, glm_strength],
310
+ outputs=[glm_output]
311
+ )
312
+
313
  with gr.Tab("๐ŸŽฎ 3D Generation"):
314
  gr.Markdown("### Generate 3D Model")
315
  gr.Markdown("Choose your engine. **Trellis** provides textures but is experimental. **Hunyuan** is geometry only.")
requirements.txt CHANGED
@@ -10,3 +10,4 @@ git+https://github.com/Tencent/Hunyuan3D-2.git
10
  diffusers
11
  accelerate
12
  trimesh
 
 
10
  diffusers
11
  accelerate
12
  trimesh
13
+ huggingface_hub