im commited on
Commit
0fcf1c4
·
1 Parent(s): 8aa5be2
Files changed (2) hide show
  1. app.py +1 -10
  2. requirements.txt +1 -0
app.py CHANGED
@@ -41,24 +41,17 @@ class ProcessRequest(BaseModel):
41
  def download_image_as_pil(url: str, timeout: int = 10) -> Image.Image:
42
  try:
43
  response = requests.get(url, stream=True, headers=REQUESTS_HEADERS, timeout=timeout)
44
- print(f"URL: {url}, Status Code: {response.status_code}, Content-Type: {response.headers.get('Content-Type')}")
45
-
46
  if response.status_code == 200 and 'image' in response.headers.get('Content-Type', ''):
47
  try:
48
- with open("temp_image.jpg", "wb") as f:
49
- f.write(response.content) # Save the image to a temporary file
50
- return Image.open("temp_image.jpg").convert("RGB")
51
  except UnidentifiedImageError:
52
  print(f"Unidentified image file from URL: {url}")
53
- else:
54
- print(f"Non-image content for URL: {url}")
55
  return None
56
  except Exception as e:
57
  print(f"Error downloading image: {e}")
58
  return None
59
 
60
 
61
-
62
  def process_batch(batch_products, batch_images, results):
63
  try:
64
  # Generate embeddings
@@ -172,8 +165,6 @@ async def process_images(request: ProcessRequest):
172
  async def health_check():
173
  return {"status": "healthy"}
174
 
175
-
176
- ##Local test
177
  # if __name__ == "__main__":
178
  # import uvicorn
179
  # uvicorn.run(app, host="0.0.0.0", port=8000)
 
41
  def download_image_as_pil(url: str, timeout: int = 10) -> Image.Image:
42
  try:
43
  response = requests.get(url, stream=True, headers=REQUESTS_HEADERS, timeout=timeout)
 
 
44
  if response.status_code == 200 and 'image' in response.headers.get('Content-Type', ''):
45
  try:
46
+ return Image.open(response.raw).convert("RGB")
 
 
47
  except UnidentifiedImageError:
48
  print(f"Unidentified image file from URL: {url}")
 
 
49
  return None
50
  except Exception as e:
51
  print(f"Error downloading image: {e}")
52
  return None
53
 
54
 
 
55
  def process_batch(batch_products, batch_images, results):
56
  try:
57
  # Generate embeddings
 
165
  async def health_check():
166
  return {"status": "healthy"}
167
 
 
 
168
  # if __name__ == "__main__":
169
  # import uvicorn
170
  # uvicorn.run(app, host="0.0.0.0", port=8000)
requirements.txt CHANGED
@@ -10,6 +10,7 @@ datasets
10
  Pillow
11
  python-dotenv
12
  tqdm
 
13
 
14
  # WooCommerce API
15
  woocommerce
 
10
  Pillow
11
  python-dotenv
12
  tqdm
13
+ fastapi
14
 
15
  # WooCommerce API
16
  woocommerce