devbucky commited on
Commit
e944a0a
·
verified ·
1 Parent(s): 6ee214a

resolved mediapipe.solutions error

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -3,7 +3,7 @@ import cv2
3
  import numpy as np
4
  from PIL import Image
5
  import mediapipe as mp
6
- import google.generativeai as genai
7
  import os
8
  import replicate
9
  import base64
@@ -262,7 +262,7 @@ def image_to_data_uri(image: Image.Image):
262
  # ============================================
263
 
264
  def run_sdxl_inpainting(original_image, mask_image, prompt, replicate_api_key):
265
- """Model 1: SDXL Inpainting (Lucataco) - Uses: image + mask + prompt"""
266
  try:
267
  os.environ["REPLICATE_API_TOKEN"] = replicate_api_key.strip()
268
 
@@ -272,18 +272,16 @@ def run_sdxl_inpainting(original_image, mask_image, prompt, replicate_api_key):
272
  image_uri = image_to_data_uri(original_image)
273
  mask_uri = image_to_data_uri(mask_image)
274
 
275
- negative_prompt = "changed eyes, changed lips, changed eyebrows, changed skin color, changed facial structure, different person, altered background, modified lighting, different hairstyle, changed expression"
276
-
277
  output = replicate.run(
278
- "lucataco/sdxl-inpainting:a5b13068cc81a89a4fbeefeccc774869fcb34df4dbc92c1555e0f2771d49dde7",
279
  input={
280
  "image": image_uri,
281
  "mask": mask_uri,
282
  "prompt": prompt,
283
- "negative_prompt": negative_prompt,
284
- "num_inference_steps": 50,
285
- "guidance_scale": 8,
286
- "strength": 0.95,
287
  }
288
  )
289
 
@@ -296,7 +294,7 @@ def run_sdxl_inpainting(original_image, mask_image, prompt, replicate_api_key):
296
 
297
  response = requests.get(image_url)
298
  result_image = Image.open(BytesIO(response.content))
299
- return result_image, "✓ SDXL Inpainting completed!"
300
  else:
301
  return None, "No output from model."
302
 
@@ -435,7 +433,7 @@ def rhinoplasty_pipeline(image, modification_text, use_gemini_enhancer, gemini_a
435
  status_log.append(f"\n\nStep 4: Running {model_choice}...")
436
  status_log.append(" (This may take 20-60 seconds...)")
437
 
438
- if model_choice == "Lucataco SDXL Inpainting":
439
  result, result_msg = run_sdxl_inpainting(image, mask, prompt, replicate_api_key)
440
  elif model_choice == "Flux Fill Pro (Premium)":
441
  result, result_msg = run_flux_fill_pro(image, mask, prompt, replicate_api_key)
@@ -462,7 +460,6 @@ default_replicate_key = os.getenv("REPLICATE_API_TOKEN", "")
462
 
463
  iface = gr.Interface(
464
  fn=rhinoplasty_pipeline,
465
- # THIS LINE IS KEY:
466
  api_name="predict",
467
  inputs=[
468
  gr.Image(type="pil", label="Upload Face Image"),
@@ -494,11 +491,11 @@ iface = gr.Interface(
494
  gr.Dropdown(
495
  label="Select AI Model",
496
  choices=[
497
- "Lucataco SDXL Inpainting",
498
  "Flux Fill Pro (Premium)",
499
  "Bria GenFill (Budget)"
500
  ],
501
- value="Flux Fill Pro (Premium)",
502
  info="Choose your preferred model"
503
  )
504
  ],
@@ -514,4 +511,10 @@ iface = gr.Interface(
514
  )
515
 
516
  if __name__ == "__main__":
517
- iface.launch()
 
 
 
 
 
 
 
3
  import numpy as np
4
  from PIL import Image
5
  import mediapipe as mp
6
+ import google.genai as genai
7
  import os
8
  import replicate
9
  import base64
 
262
  # ============================================
263
 
264
  def run_sdxl_inpainting(original_image, mask_image, prompt, replicate_api_key):
265
+ """Model 1: Flux Fill Dev - Uses: image + mask + prompt"""
266
  try:
267
  os.environ["REPLICATE_API_TOKEN"] = replicate_api_key.strip()
268
 
 
272
  image_uri = image_to_data_uri(original_image)
273
  mask_uri = image_to_data_uri(mask_image)
274
 
 
 
275
  output = replicate.run(
276
+ "black-forest-labs/flux-fill-dev",
277
  input={
278
  "image": image_uri,
279
  "mask": mask_uri,
280
  "prompt": prompt,
281
+ "guidance": 33,
282
+ "steps": 28,
283
+ "output_format": "png",
284
+ "output_quality": 95
285
  }
286
  )
287
 
 
294
 
295
  response = requests.get(image_url)
296
  result_image = Image.open(BytesIO(response.content))
297
+ return result_image, "✓ Flux Fill Dev completed!"
298
  else:
299
  return None, "No output from model."
300
 
 
433
  status_log.append(f"\n\nStep 4: Running {model_choice}...")
434
  status_log.append(" (This may take 20-60 seconds...)")
435
 
436
+ if model_choice == "Flux Fill Dev (Recommended)":
437
  result, result_msg = run_sdxl_inpainting(image, mask, prompt, replicate_api_key)
438
  elif model_choice == "Flux Fill Pro (Premium)":
439
  result, result_msg = run_flux_fill_pro(image, mask, prompt, replicate_api_key)
 
460
 
461
  iface = gr.Interface(
462
  fn=rhinoplasty_pipeline,
 
463
  api_name="predict",
464
  inputs=[
465
  gr.Image(type="pil", label="Upload Face Image"),
 
491
  gr.Dropdown(
492
  label="Select AI Model",
493
  choices=[
494
+ "Flux Fill Dev (Recommended)",
495
  "Flux Fill Pro (Premium)",
496
  "Bria GenFill (Budget)"
497
  ],
498
+ value="Flux Fill Dev (Recommended)",
499
  info="Choose your preferred model"
500
  )
501
  ],
 
511
  )
512
 
513
  if __name__ == "__main__":
514
+ # Launch with explicit settings for Hugging Face Spaces
515
+ iface.launch(
516
+ server_name="0.0.0.0",
517
+ server_port=7860,
518
+ show_error=True,
519
+ quiet=False
520
+ )