tejani commited on
Commit
b7f67b2
·
verified ·
1 Parent(s): 23420d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -32
app.py CHANGED
@@ -42,52 +42,33 @@ async def try_on(
42
  shutil.copyfileobj(garment_img.file, f)
43
 
44
  # Generate public URLs (assuming the Space is hosted at a public URL)
45
- # Replace YOUR_SPACE_URL with the actual Hugging Face Space URL
46
- base_url = "https://tejani-tryapi.hf.space" # e.g., https://your-username-your-space.hf.space
47
  human_url = f"{base_url}/static/{human_filename}"
48
  garment_url = f"{base_url}/static/{garment_filename}"
49
 
50
  # Prepare headers and data for the original API
51
- headers = {
52
- "accept": "*/*",
53
- "accept-language": "en-GB,en-US;q=0.9,en;q=0.8,gu;q=0.7",
54
- "content-type": "multipart/form-data; boundary=----WebKitFormBoundary90rchhPtvEuSQa34",
55
- "f": "b5626a38c4ffbcef3199241f38c94361",
56
- "origin": "https://changeclothesai.online",
57
- "referer": "https://changeclothesai.online/",
58
- "sec-ch-ua": '"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"',
59
- "sec-ch-ua-mobile": "?1",
60
- "sec-ch-ua-platform": '"Android"',
61
- "sec-fetch-dest": "empty",
62
- "sec-fetch-mode": "cors",
63
- "sec-fetch-site": "same-origin",
64
- "user-agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36"
65
  }
66
 
67
- data = (
68
- '------WebKitFormBoundary90rchhPtvEuSQa34\r\n'
69
- f'Content-Disposition: form-data; name="humanImg"\r\n\r\n{human_url}\r\n'
70
- '------WebKitFormBoundary90rchhPtvEuSQa34\r\n'
71
- f'Content-Disposition: form-data; name="garment"\r\n\r\n{garment_url}\r\n'
72
- '------WebKitFormBoundary90rchhPtvEuSQa34\r\n'
73
- f'Content-Disposition: form-data; name="garmentDesc"\r\n\r\n{garment_desc}\r\n'
74
- '------WebKitFormBoundary90rchhPtvEuSQa34\r\n'
75
- f'Content-Disposition: form-data; name="category"\r\n\r\n{category}\r\n'
76
- '------WebKitFormBoundary90rchhPtvEuSQa34--\r\n'
77
- )
78
 
79
  # Call the ChangeClothesAI API
80
- response = requests.post(CHANGE_CLOTHES_API, headers=headers, data=data)
81
 
82
  # Check if the API call was successful
83
  if response.status_code != 200:
84
  raise HTTPException(status_code=response.status_code, detail="Error calling ChangeClothesAI API")
85
 
86
  # Delete temporary files
87
- #os.remove(human_path)
88
- print(human_url)
89
- print(garment_url)
90
- #os.remove(garment_path)
91
 
92
  return response.json()
93
 
 
42
  shutil.copyfileobj(garment_img.file, f)
43
 
44
  # Generate public URLs (assuming the Space is hosted at a public URL)
45
+ base_url = "https://tejani-tryapi.hf.space"
 
46
  human_url = f"{base_url}/static/{human_filename}"
47
  garment_url = f"{base_url}/static/{garment_filename}"
48
 
49
  # Prepare headers and data for the original API
50
+ headers = {
51
+ "accept": "*/*",
52
+ "f": str(uuid.uuid4()).replace("-", ""),
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
 
55
+ data = {
56
+ "humanImg": human_url,
57
+ "garment": garment_url,
58
+ "garmentDesc": garment_desc,
59
+ "category": category,
60
+ }
 
 
 
 
 
61
 
62
  # Call the ChangeClothesAI API
63
+ response = requests.post(CHANGE_CLOTHES_API, headers=headers, data=data, timeout=60)
64
 
65
  # Check if the API call was successful
66
  if response.status_code != 200:
67
  raise HTTPException(status_code=response.status_code, detail="Error calling ChangeClothesAI API")
68
 
69
  # Delete temporary files
70
+ os.remove(human_path)
71
+ os.remove(garment_path)
 
 
72
 
73
  return response.json()
74