tejani commited on
Commit
bb37d17
·
verified ·
1 Parent(s): a842a46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -25
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
- # Test URL accessibility
59
- time.sleep(1) # Ensure files are available
60
- try:
61
- url_check = requests.head(human_url, timeout=5)
62
- logger.info(f"Human URL status: {url_check.status_code}")
63
- if url_check.status_code != 200:
64
- raise HTTPException(status_code=500, detail=f"Human image URL inaccessible: {human_url}")
65
- url_check = requests.head(garment_url, timeout=5)
66
- logger.info(f"Garment URL status: {url_check.status_code}")
67
- if url_check.status_code != 200:
68
- raise HTTPException(status_code=500, detail=f"Garment image URL inaccessible: {garment_url}")
69
- except requests.RequestException as e:
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": str(uuid.uuid4()).replace("-", ""),
76
  }
77
- cookies = {} # Add empty cookies to match the first script
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
- os.remove(human_path)
105
- if os.path.exists(garment_path):
106
- os.remove(garment_path)
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