Monikashyapa commited on
Commit
481ce32
·
verified ·
1 Parent(s): 8a28709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -1,8 +1,14 @@
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
 
4
  from gradio_client import Client
5
 
 
 
 
 
 
6
  # -----------------------------
7
  # Local "try-on" function
8
  # -----------------------------
@@ -45,14 +51,14 @@ def tryon_to_3d(person_img, garment_img, seed, randomize_seed):
45
  return None, "Try-on failed"
46
 
47
  try:
48
- # Convert NumPy arrays to PNG bytes
49
- _, tryon_bytes = cv2.imencode('.png', tryon_img)
50
- _, garment_bytes = cv2.imencode('.png', garment_img)
51
 
52
- # Send bytes (Hunyuan3D Gradio API accepts file-like input)
53
  result_3d = hunyuan_client.predict(
54
- tryon_bytes.tobytes(),
55
- garment_bytes.tobytes(),
56
  fn_index=fn_index_default
57
  )
58
  return result_3d, tryon_info
 
1
  import gradio as gr
2
  import cv2
3
  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
  # -----------------------------
 
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