Update app.py
Browse files
app.py
CHANGED
@@ -49,32 +49,31 @@ async def try_on(
|
|
49 |
logger.info(f"Garment image saved: {os.path.exists(garment_path)}")
|
50 |
|
51 |
# Generate public URLs
|
52 |
-
base_url = "https://tejani-tryapi.hf.space"
|
53 |
human_url = f"{base_url}/static/{human_filename}"
|
54 |
garment_url = f"{base_url}/static/{garment_filename}"
|
55 |
logger.info(f"Human URL: {human_url}")
|
56 |
logger.info(f"Garment URL: {garment_url}")
|
57 |
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
raise HTTPException(status_code=500, detail=f"Error accessing URLs: {str(e)}")
|
71 |
|
72 |
# Prepare headers, cookies, and data for the API
|
73 |
headers = {
|
74 |
"accept": "*/*",
|
75 |
-
"f":
|
76 |
}
|
77 |
-
cookies = {}
|
78 |
data = {
|
79 |
"humanImg": human_url,
|
80 |
"garment": garment_url,
|
@@ -91,19 +90,19 @@ async def try_on(
|
|
91 |
if response.status_code != 200:
|
92 |
raise HTTPException(status_code=response.status_code, detail=f"Error calling ChangeClothesAI API: {response.text}")
|
93 |
|
94 |
-
# Delete temporary files
|
95 |
-
os.remove(human_path)
|
96 |
-
os.remove(garment_path)
|
97 |
-
logger.info("Temporary files deleted")
|
98 |
|
99 |
return response.json()
|
100 |
|
101 |
except Exception as e:
|
102 |
-
# Clean up in case of errors
|
103 |
-
if os.path.exists(human_path):
|
104 |
-
|
105 |
-
if os.path.exists(garment_path):
|
106 |
-
|
107 |
logger.error(f"Error processing request: {str(e)}")
|
108 |
raise HTTPException(status_code=500, detail=f"Error processing files: {str(e)}")
|
109 |
|
|
|
49 |
logger.info(f"Garment image saved: {os.path.exists(garment_path)}")
|
50 |
|
51 |
# Generate public URLs
|
52 |
+
base_url = "https://tejani-tryapi.hf.space" # Verify this is correct
|
53 |
human_url = f"{base_url}/static/{human_filename}"
|
54 |
garment_url = f"{base_url}/static/{garment_filename}"
|
55 |
logger.info(f"Human URL: {human_url}")
|
56 |
logger.info(f"Garment URL: {garment_url}")
|
57 |
|
58 |
+
# Skip URL verification for debugging
|
59 |
+
# try:
|
60 |
+
# url_check = requests.head(human_url, timeout=10)
|
61 |
+
# logger.info(f"Human URL status: {url_check.status_code}")
|
62 |
+
# if url_check.status_code != 200:
|
63 |
+
# raise HTTPException(status_code=500, detail=f"Human image URL inaccessible: {human_url}")
|
64 |
+
# url_check = requests.head(garment_url, timeout=10)
|
65 |
+
# logger.info(f"Garment URL status: {url_check.status_code}")
|
66 |
+
# if url_check.status_code != 200:
|
67 |
+
# raise HTTPException(status_code=500, detail=f"Garment image URL inaccessible: {garment_url}")
|
68 |
+
# except requests.RequestException as e:
|
69 |
+
# raise HTTPException(status_code=500, detail=f"Error accessing URLs: {str(e)}")
|
|
|
70 |
|
71 |
# Prepare headers, cookies, and data for the API
|
72 |
headers = {
|
73 |
"accept": "*/*",
|
74 |
+
"f": "sdfdsfsKaVgUoxa5j1jzcFtziPx", # Match Trinket script
|
75 |
}
|
76 |
+
cookies = {}
|
77 |
data = {
|
78 |
"humanImg": human_url,
|
79 |
"garment": garment_url,
|
|
|
90 |
if response.status_code != 200:
|
91 |
raise HTTPException(status_code=response.status_code, detail=f"Error calling ChangeClothesAI API: {response.text}")
|
92 |
|
93 |
+
# Delete temporary files (commented out for debugging)
|
94 |
+
# os.remove(human_path)
|
95 |
+
# os.remove(garment_path)
|
96 |
+
# logger.info("Temporary files deleted")
|
97 |
|
98 |
return response.json()
|
99 |
|
100 |
except Exception as e:
|
101 |
+
# Clean up in case of errors (commented out for debugging)
|
102 |
+
# if os.path.exists(human_path):
|
103 |
+
# os.remove(human_path)
|
104 |
+
# if os.path.exists(garment_path):
|
105 |
+
# os.remove(garment_path)
|
106 |
logger.error(f"Error processing request: {str(e)}")
|
107 |
raise HTTPException(status_code=500, detail=f"Error processing files: {str(e)}")
|
108 |
|