Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,19 @@ import time
|
|
| 8 |
import random
|
| 9 |
import os
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def tryon(person_img, garment_img, seed, randomize_seed):
|
| 13 |
if person_img is None or garment_img is None:
|
| 14 |
st.warning("Empty image")
|
|
@@ -21,11 +33,7 @@ def tryon(person_img, garment_img, seed, randomize_seed):
|
|
| 21 |
encoded_garment_img = cv2.imencode('.jpg', cv2.cvtColor(garment_img, cv2.COLOR_RGB2BGR))[1].tobytes()
|
| 22 |
encoded_garment_img = base64.b64encode(encoded_garment_img).decode('utf-8')
|
| 23 |
|
| 24 |
-
url =
|
| 25 |
-
token = os.environ['token']
|
| 26 |
-
cookie = os.environ['Cookie']
|
| 27 |
-
referer = os.environ['referer']
|
| 28 |
-
headers = {'Content-Type': 'application/json', 'token': token, 'Cookie': cookie, 'referer': referer}
|
| 29 |
data = {
|
| 30 |
"clothImage": encoded_garment_img,
|
| 31 |
"humanImage": encoded_person_img,
|
|
@@ -48,7 +56,7 @@ def tryon(person_img, garment_img, seed, randomize_seed):
|
|
| 48 |
info = ""
|
| 49 |
for i in range(Max_Retry):
|
| 50 |
try:
|
| 51 |
-
url =
|
| 52 |
response = requests.get(url, headers=headers, timeout=20)
|
| 53 |
if response.status_code == 200:
|
| 54 |
result = response.json()['result']
|
|
@@ -90,7 +98,6 @@ st.markdown("""
|
|
| 90 |
This project leverages the advanced virtual try-on model by Kwai-Kolors. We've created a simple and interactive GUI for users to experience virtual try-ons. For more innovative features and models, check out Kwai-Kolors on their official website!
|
| 91 |
|
| 92 |
[Explore Kwai-Kolors' website](https://klingai.com/)
|
| 93 |
-
|
| 94 |
""")
|
| 95 |
|
| 96 |
# Display the demo image
|
|
|
|
| 8 |
import random
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
# Load environment variables
|
| 12 |
+
tryon_url = os.environ.get('tryon_url', 'http://default-url/') # Default URL for testing
|
| 13 |
+
token = os.environ.get('token', 'default-token')
|
| 14 |
+
cookie = os.environ.get('Cookie', 'default-cookie')
|
| 15 |
+
referer = os.environ.get('referer', 'default-referer')
|
| 16 |
+
|
| 17 |
+
headers = {
|
| 18 |
+
'Content-Type': 'application/json',
|
| 19 |
+
'token': token,
|
| 20 |
+
'Cookie': cookie,
|
| 21 |
+
'referer': referer
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
def tryon(person_img, garment_img, seed, randomize_seed):
|
| 25 |
if person_img is None or garment_img is None:
|
| 26 |
st.warning("Empty image")
|
|
|
|
| 33 |
encoded_garment_img = cv2.imencode('.jpg', cv2.cvtColor(garment_img, cv2.COLOR_RGB2BGR))[1].tobytes()
|
| 34 |
encoded_garment_img = base64.b64encode(encoded_garment_img).decode('utf-8')
|
| 35 |
|
| 36 |
+
url = tryon_url + "Submit"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
data = {
|
| 38 |
"clothImage": encoded_garment_img,
|
| 39 |
"humanImage": encoded_person_img,
|
|
|
|
| 56 |
info = ""
|
| 57 |
for i in range(Max_Retry):
|
| 58 |
try:
|
| 59 |
+
url = tryon_url + "Query?taskId=" + uuid
|
| 60 |
response = requests.get(url, headers=headers, timeout=20)
|
| 61 |
if response.status_code == 200:
|
| 62 |
result = response.json()['result']
|
|
|
|
| 98 |
This project leverages the advanced virtual try-on model by Kwai-Kolors. We've created a simple and interactive GUI for users to experience virtual try-ons. For more innovative features and models, check out Kwai-Kolors on their official website!
|
| 99 |
|
| 100 |
[Explore Kwai-Kolors' website](https://klingai.com/)
|
|
|
|
| 101 |
""")
|
| 102 |
|
| 103 |
# Display the demo image
|