Monikashyapa commited on
Commit
7bf4efc
·
verified ·
1 Parent(s): 481ce32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -4,13 +4,15 @@ import numpy as np
4
  import base64
5
  from gradio_client import Client
6
 
7
- def np_to_base64(img_np):
8
- _, buffer = cv2.imencode('.png', img_np)
9
- img_bytes = buffer.tobytes()
10
- return "data:image/png;base64," + base64.b64encode(img_bytes).decode()
 
 
11
 
12
  # -----------------------------
13
- # Local "try-on" function
14
  # -----------------------------
15
  def tryon_local(person_img, garment_img, seed, randomize_seed):
16
  if person_img is None or garment_img is None:
@@ -43,25 +45,23 @@ def tryon_local(person_img, garment_img, seed, randomize_seed):
43
  # Hunyuan3D API client
44
  # -----------------------------
45
  hunyuan_client = Client("tencent/Hunyuan3D-2.1")
 
 
46
  fn_index_default = hunyuan_client.endpoints[0].fn_index if hunyuan_client.endpoints else 0
47
 
48
  def tryon_to_3d(person_img, garment_img, seed, randomize_seed):
 
49
  tryon_img, seed_used, tryon_info = tryon_local(person_img, garment_img, seed, randomize_seed)
50
  if tryon_img is None:
51
  return None, "Try-on failed"
52
 
53
  try:
54
- # Convert images to base64 strings
55
- person_base64 = np_to_base64(tryon_img)
56
- garment_base64 = np_to_base64(garment_img)
57
-
58
- # Send base64 images to Hunyuan3D API
59
- result_3d = hunyuan_client.predict(
60
- person_base64,
61
- garment_base64,
62
- fn_index=fn_index_default
63
- )
64
- return result_3d, tryon_info
65
  except Exception as e:
66
  return None, f"Hunyuan3D API error: {e}"
67
 
 
4
  import base64
5
  from gradio_client import Client
6
 
7
+ # -----------------------------
8
+ # Helper: Convert NumPy image to base64
9
+ # -----------------------------
10
+ def np_to_base64(img):
11
+ _, buffer = cv2.imencode(".png", img)
12
+ return base64.b64encode(buffer).decode("utf-8")
13
 
14
  # -----------------------------
15
+ # Local "try-on" simulation
16
  # -----------------------------
17
  def tryon_local(person_img, garment_img, seed, randomize_seed):
18
  if person_img is None or garment_img is None:
 
45
  # Hunyuan3D API client
46
  # -----------------------------
47
  hunyuan_client = Client("tencent/Hunyuan3D-2.1")
48
+
49
+ # Get default fn_index
50
  fn_index_default = hunyuan_client.endpoints[0].fn_index if hunyuan_client.endpoints else 0
51
 
52
  def tryon_to_3d(person_img, garment_img, seed, randomize_seed):
53
+ # Run local try-on first
54
  tryon_img, seed_used, tryon_info = tryon_local(person_img, garment_img, seed, randomize_seed)
55
  if tryon_img is None:
56
  return None, "Try-on failed"
57
 
58
  try:
59
+ # Convert image to base64 for API
60
+ img_b64 = np_to_base64(tryon_img)
61
+
62
+ # Hunyuan3D API only accepts positional arguments (list)
63
+ result = hunyuan_client.predict([img_b64], fn_index=fn_index_default)
64
+ return result, tryon_info
 
 
 
 
 
65
  except Exception as e:
66
  return None, f"Hunyuan3D API error: {e}"
67