insideman commited on
Commit
73cb919
·
verified ·
1 Parent(s): c7354ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -8,6 +8,11 @@ import requests
8
  import json
9
  import time
10
 
 
 
 
 
 
11
 
12
  def tryon(person_img, garment_img, seed, randomize_seed):
13
  post_start_time = time.time()
@@ -16,21 +21,29 @@ def tryon(person_img, garment_img, seed, randomize_seed):
16
  return None, None, "Empty image"
17
  if randomize_seed:
18
  seed = random.randint(0, MAX_SEED)
 
 
19
  encoded_person_img = cv2.imencode('.jpg', cv2.cvtColor(person_img, cv2.COLOR_RGB2BGR))[1].tobytes()
20
  encoded_person_img = base64.b64encode(encoded_person_img).decode('utf-8')
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 = "http://" + os.environ['tryon_url'] + "Submit"
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,
32
  "seed": seed
33
  }
 
 
34
  try:
35
  response = requests.post(url, headers=headers, data=json.dumps(data), timeout=50)
36
  # print("post response code", response.status_code)
 
8
  import json
9
  import time
10
 
11
+ # Hugging Face Secrets'dan environment variables'ları al
12
+ TRYON_URL = os.getenv('TRYON_URL', 'default_url/')
13
+ TOKEN = os.getenv('TOKEN', 'default_token')
14
+ COOKIE = os.getenv('COOKIE', 'default_cookie')
15
+ REFERER = os.getenv('REFERER', 'default_referer')
16
 
17
  def tryon(person_img, garment_img, seed, randomize_seed):
18
  post_start_time = time.time()
 
21
  return None, None, "Empty image"
22
  if randomize_seed:
23
  seed = random.randint(0, MAX_SEED)
24
+
25
+ # Resim kodlama
26
  encoded_person_img = cv2.imencode('.jpg', cv2.cvtColor(person_img, cv2.COLOR_RGB2BGR))[1].tobytes()
27
  encoded_person_img = base64.b64encode(encoded_person_img).decode('utf-8')
28
  encoded_garment_img = cv2.imencode('.jpg', cv2.cvtColor(garment_img, cv2.COLOR_RGB2BGR))[1].tobytes()
29
  encoded_garment_img = base64.b64encode(encoded_garment_img).decode('utf-8')
30
 
31
+ # URL ve headers
32
+ url = f"http://{TRYON_URL}Submit"
33
+ headers = {
34
+ 'Content-Type': 'application/json',
35
+ 'token': TOKEN,
36
+ 'Cookie': COOKIE,
37
+ 'referer': REFERER
38
+ }
39
+
40
  data = {
41
  "clothImage": encoded_garment_img,
42
  "humanImage": encoded_person_img,
43
  "seed": seed
44
  }
45
+
46
+
47
  try:
48
  response = requests.post(url, headers=headers, data=json.dumps(data), timeout=50)
49
  # print("post response code", response.status_code)