LiamKhoaLe commited on
Commit
66e3d42
·
1 Parent(s): 6a3e20a

Try to send image not JSON

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -305,13 +305,18 @@ def stream(uid:str):
305
  # https://universe.roboflow.com/team-hope-mmcyy/hydroquest | https://universe.roboflow.com/sky-sd2zq/bird_only-pt0bm/model/1
306
  import base64, requests
307
  def roboflow_infer(image_path, api_url, api_key):
308
- with open(image_path, "rb") as f:
309
- img_b64 = base64.b64encode(f.read()).decode()
310
- res = requests.post(api_url, json={
311
- "api_key": api_key,
312
- "image": img_b64
313
- }, headers={"Content-Type": "application/json"})
314
- return res.json()
 
 
 
 
 
315
 
316
  # Animal detection endpoint (animal, fish, bird as target classes)
317
  @app.post("/animal/")
@@ -340,6 +345,9 @@ async def detect_animals(file: UploadFile = File(...)):
340
  except Exception as e:
341
  print("[YOLOv8 Error]", e)
342
 
 
 
 
343
  # 2. Roboflow Fish
344
  try:
345
  print("[Animal] Detecting via Roboflow Fish model…")
 
305
  # https://universe.roboflow.com/team-hope-mmcyy/hydroquest | https://universe.roboflow.com/sky-sd2zq/bird_only-pt0bm/model/1
306
  import base64, requests
307
  def roboflow_infer(image_path, api_url, api_key):
308
+ with open(image_path, "rb") as image_file:
309
+ files = {"file": image_file}
310
+ res = requests.post(
311
+ f"{api_url}?api_key={api_key}&confidence=70", # Add threshold to URL
312
+ files=files
313
+ )
314
+ print(f"[Roboflow] {res.status_code} response")
315
+ try:
316
+ return res.json()
317
+ except Exception as e:
318
+ print("[Roboflow JSON decode error]", e)
319
+ return {}
320
 
321
  # Animal detection endpoint (animal, fish, bird as target classes)
322
  @app.post("/animal/")
 
345
  except Exception as e:
346
  print("[YOLOv8 Error]", e)
347
 
348
+ # Hide on production-level
349
+ print("[API] Roboflow key:", os.getenv("ROBOFLOW_KEY", "❌ not set"))
350
+
351
  # 2. Roboflow Fish
352
  try:
353
  print("[Animal] Detecting via Roboflow Fish model…")