Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,42 @@
|
|
1 |
import os
|
2 |
import cv2
|
3 |
-
import spaces
|
4 |
-
from PIL import Image
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
import random
|
8 |
-
import base64
|
9 |
-
import requests
|
10 |
-
import json
|
11 |
import time
|
12 |
|
13 |
-
|
14 |
def tryon(person_img, garment_prompt, seed, randomize_seed):
|
15 |
post_start_time = time.time()
|
|
|
16 |
if person_img is None or garment_prompt.strip() == "":
|
17 |
return None, None, "Empty image or prompt"
|
|
|
18 |
if randomize_seed:
|
19 |
seed = random.randint(0, MAX_SEED)
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
#
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
# Decoding process (dummy)
|
35 |
-
result_img = cv2.imdecode(np.frombuffer(base64.b64decode(encoded_garment_img), np.uint8), cv2.IMREAD_UNCHANGED)
|
36 |
-
result_img = cv2.cvtColor(result_img, cv2.COLOR_RGB2BGR)
|
37 |
|
38 |
post_end_time = time.time()
|
39 |
print(f"post time used: {post_end_time - post_start_time}")
|
40 |
|
41 |
-
# Return the
|
42 |
return result_img, seed, "Success"
|
43 |
|
44 |
-
|
45 |
MAX_SEED = 999999
|
46 |
|
47 |
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
|
|
1 |
import os
|
2 |
import cv2
|
|
|
|
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import random
|
|
|
|
|
|
|
6 |
import time
|
7 |
|
|
|
8 |
def tryon(person_img, garment_prompt, seed, randomize_seed):
|
9 |
post_start_time = time.time()
|
10 |
+
|
11 |
if person_img is None or garment_prompt.strip() == "":
|
12 |
return None, None, "Empty image or prompt"
|
13 |
+
|
14 |
if randomize_seed:
|
15 |
seed = random.randint(0, MAX_SEED)
|
16 |
|
17 |
+
# Create a copy of the person image to overlay text
|
18 |
+
result_img = person_img.copy()
|
19 |
|
20 |
+
# Convert the image to OpenCV format (if needed)
|
21 |
+
if len(result_img.shape) == 2: # Convert grayscale to RGB
|
22 |
+
result_img = cv2.cvtColor(result_img, cv2.COLOR_GRAY2RGB)
|
23 |
|
24 |
+
# Set text position and properties
|
25 |
+
text_position = (10, 30)
|
26 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
27 |
+
font_scale = 1
|
28 |
+
font_color = (0, 255, 0) # Green color for the text
|
29 |
+
thickness = 2
|
30 |
|
31 |
+
# Overlay the garment description text on the image
|
32 |
+
cv2.putText(result_img, f'Garment: {garment_prompt}', text_position, font, font_scale, font_color, thickness, cv2.LINE_AA)
|
|
|
|
|
|
|
|
|
33 |
|
34 |
post_end_time = time.time()
|
35 |
print(f"post time used: {post_end_time - post_start_time}")
|
36 |
|
37 |
+
# Return the resulting image, used seed, and success message
|
38 |
return result_img, seed, "Success"
|
39 |
|
|
|
40 |
MAX_SEED = 999999
|
41 |
|
42 |
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|