Spaces:
Runtime error
Runtime error
Commit Β·
e383c7d
1
Parent(s): 4ea7bfb
fix: import facemeshdetector and remove logger
Browse files- app.py +2 -10
- choker/necklace_1.png +0 -3
- choker/necklace_11.png +0 -3
- choker/necklace_12.png +0 -3
- choker/necklace_20.png +0 -3
- choker/necklace_27.png +0 -3
- choker/necklace_29.png +0 -3
- choker/necklace_48.png +0 -3
- choker/necklace_51.png +0 -3
- choker/necklace_56.png +0 -3
- choker/necklace_8.png +0 -3
- long_haram/necklace_1.png +0 -0
- long_haram/necklace_10.png +0 -0
- long_haram/necklace_2.png +0 -0
- long_haram/necklace_3.png +0 -0
- long_haram/necklace_4.png +0 -0
- long_haram/necklace_5.png +0 -0
- long_haram/necklace_6.png +0 -0
- long_haram/necklace_7.png +0 -0
- long_haram/necklace_8.png +0 -0
- long_haram/necklace_9.png +0 -3
app.py
CHANGED
|
@@ -11,9 +11,10 @@ import gc
|
|
| 11 |
import math
|
| 12 |
import cvzone
|
| 13 |
from cvzone.PoseModule import PoseDetector
|
|
|
|
| 14 |
import spaces
|
| 15 |
|
| 16 |
-
choker_images = [Image.open(os.path.join("
|
| 17 |
person_images = [Image.open(os.path.join("without_necklace", x)) for x in os.listdir("without_necklace")]
|
| 18 |
|
| 19 |
model_id = "stabilityai/stable-diffusion-2-inpainting"
|
|
@@ -38,8 +39,6 @@ def clothing_try_on_n_necklace_try_on(image, jewellery):
|
|
| 38 |
copy_image = image.copy()
|
| 39 |
jewellery = np.array(jewellery)
|
| 40 |
|
| 41 |
-
logger.info(f"NECKLACE TRY ON :: detecting pose and landmarks :: {storename}")
|
| 42 |
-
|
| 43 |
image = detector.findPose(image)
|
| 44 |
lmList, _ = detector.findPosition(image, bboxWithHands=False, draw=False)
|
| 45 |
|
|
@@ -51,7 +50,6 @@ def clothing_try_on_n_necklace_try_on(image, jewellery):
|
|
| 51 |
landmarksDistance = int(
|
| 52 |
((leftLandmark[0] - rightLandmark[0]) ** 2 + (leftLandmark[1] - rightLandmark[1]) ** 2) ** 0.5)
|
| 53 |
|
| 54 |
-
logger.info(f"NECKLACE TRY ON :: estimating neck points")
|
| 55 |
|
| 56 |
avg_x1 = int(leftLandmark[0] - landmarksDistance * 0.12)
|
| 57 |
avg_x2 = int(rightLandmark[0] + landmarksDistance * 0.12)
|
|
@@ -59,7 +57,6 @@ def clothing_try_on_n_necklace_try_on(image, jewellery):
|
|
| 59 |
avg_y1 = int(leftLandmark[1] + landmarksDistance * 0.5)
|
| 60 |
avg_y2 = int(rightLandmark[1] + landmarksDistance * 0.5)
|
| 61 |
|
| 62 |
-
logger.info(f"NECKLACE TRY ON :: scaling the necklace image ")
|
| 63 |
|
| 64 |
if avg_y2 < avg_y1:
|
| 65 |
angle = math.ceil(
|
|
@@ -79,7 +76,6 @@ def clothing_try_on_n_necklace_try_on(image, jewellery):
|
|
| 79 |
origImgRatio = xdist / jewellery.shape[1]
|
| 80 |
ydist = jewellery.shape[0] * origImgRatio
|
| 81 |
|
| 82 |
-
logger.info(f"NECKLACE TRY ON :: adding offset based on the necklace shape")
|
| 83 |
|
| 84 |
image_gray = cv2.cvtColor(jewellery, cv2.COLOR_BGRA2GRAY)
|
| 85 |
for offset_orig in range(image_gray.shape[1]):
|
|
@@ -94,9 +90,6 @@ def clothing_try_on_n_necklace_try_on(image, jewellery):
|
|
| 94 |
)
|
| 95 |
jewellery = cvzone.rotateImage(jewellery, angle)
|
| 96 |
y_coordinate = avg_y1 - offset
|
| 97 |
-
|
| 98 |
-
logger.info(f"NECKLACE TRY ON :: generating output :: {storename}")
|
| 99 |
-
|
| 100 |
result = cvzone.overlayPNG(copy_image, jewellery, (avg_x1, y_coordinate))
|
| 101 |
|
| 102 |
blackedNecklace = np.zeros(shape=copy_image.shape)
|
|
@@ -176,4 +169,3 @@ with gr.Blocks() as interface:
|
|
| 176 |
submit.click(fn=clothing_try_on_n_necklace_try_on, inputs=[inputImage, selectedNecklace], outputs=[outputOne])
|
| 177 |
|
| 178 |
interface.launch(debug=True)
|
| 179 |
-
|
|
|
|
| 11 |
import math
|
| 12 |
import cvzone
|
| 13 |
from cvzone.PoseModule import PoseDetector
|
| 14 |
+
from cvzone.FaceMeshModule import FaceMeshDetector
|
| 15 |
import spaces
|
| 16 |
|
| 17 |
+
choker_images = [Image.open(os.path.join("short_necklace", x)) for x in os.listdir("short_necklace")]
|
| 18 |
person_images = [Image.open(os.path.join("without_necklace", x)) for x in os.listdir("without_necklace")]
|
| 19 |
|
| 20 |
model_id = "stabilityai/stable-diffusion-2-inpainting"
|
|
|
|
| 39 |
copy_image = image.copy()
|
| 40 |
jewellery = np.array(jewellery)
|
| 41 |
|
|
|
|
|
|
|
| 42 |
image = detector.findPose(image)
|
| 43 |
lmList, _ = detector.findPosition(image, bboxWithHands=False, draw=False)
|
| 44 |
|
|
|
|
| 50 |
landmarksDistance = int(
|
| 51 |
((leftLandmark[0] - rightLandmark[0]) ** 2 + (leftLandmark[1] - rightLandmark[1]) ** 2) ** 0.5)
|
| 52 |
|
|
|
|
| 53 |
|
| 54 |
avg_x1 = int(leftLandmark[0] - landmarksDistance * 0.12)
|
| 55 |
avg_x2 = int(rightLandmark[0] + landmarksDistance * 0.12)
|
|
|
|
| 57 |
avg_y1 = int(leftLandmark[1] + landmarksDistance * 0.5)
|
| 58 |
avg_y2 = int(rightLandmark[1] + landmarksDistance * 0.5)
|
| 59 |
|
|
|
|
| 60 |
|
| 61 |
if avg_y2 < avg_y1:
|
| 62 |
angle = math.ceil(
|
|
|
|
| 76 |
origImgRatio = xdist / jewellery.shape[1]
|
| 77 |
ydist = jewellery.shape[0] * origImgRatio
|
| 78 |
|
|
|
|
| 79 |
|
| 80 |
image_gray = cv2.cvtColor(jewellery, cv2.COLOR_BGRA2GRAY)
|
| 81 |
for offset_orig in range(image_gray.shape[1]):
|
|
|
|
| 90 |
)
|
| 91 |
jewellery = cvzone.rotateImage(jewellery, angle)
|
| 92 |
y_coordinate = avg_y1 - offset
|
|
|
|
|
|
|
|
|
|
| 93 |
result = cvzone.overlayPNG(copy_image, jewellery, (avg_x1, y_coordinate))
|
| 94 |
|
| 95 |
blackedNecklace = np.zeros(shape=copy_image.shape)
|
|
|
|
| 169 |
submit.click(fn=clothing_try_on_n_necklace_try_on, inputs=[inputImage, selectedNecklace], outputs=[outputOne])
|
| 170 |
|
| 171 |
interface.launch(debug=True)
|
|
|
choker/necklace_1.png
DELETED
Git LFS Details
|
choker/necklace_11.png
DELETED
Git LFS Details
|
choker/necklace_12.png
DELETED
Git LFS Details
|
choker/necklace_20.png
DELETED
Git LFS Details
|
choker/necklace_27.png
DELETED
Git LFS Details
|
choker/necklace_29.png
DELETED
Git LFS Details
|
choker/necklace_48.png
DELETED
Git LFS Details
|
choker/necklace_51.png
DELETED
Git LFS Details
|
choker/necklace_56.png
DELETED
Git LFS Details
|
choker/necklace_8.png
DELETED
Git LFS Details
|
long_haram/necklace_1.png
DELETED
|
Binary file (408 kB)
|
|
|
long_haram/necklace_10.png
DELETED
|
Binary file (665 kB)
|
|
|
long_haram/necklace_2.png
DELETED
|
Binary file (642 kB)
|
|
|
long_haram/necklace_3.png
DELETED
|
Binary file (821 kB)
|
|
|
long_haram/necklace_4.png
DELETED
|
Binary file (620 kB)
|
|
|
long_haram/necklace_5.png
DELETED
|
Binary file (666 kB)
|
|
|
long_haram/necklace_6.png
DELETED
|
Binary file (707 kB)
|
|
|
long_haram/necklace_7.png
DELETED
|
Binary file (561 kB)
|
|
|
long_haram/necklace_8.png
DELETED
|
Binary file (808 kB)
|
|
|
long_haram/necklace_9.png
DELETED
Git LFS Details
|