rishab1090 commited on
Commit
8a9a7e3
·
verified ·
1 Parent(s): 75ac3e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -104,6 +104,8 @@ def estimate_quantity(pred):
104
  # =====================
105
  import base64
106
 
 
 
107
  def detect(image_path):
108
  api_key = os.getenv("ROBOFLOW_API_KEY")
109
 
@@ -115,8 +117,7 @@ def detect(image_path):
115
  try:
116
  # convert image → base64
117
  with open(image_path, "rb") as f:
118
- image_bytes = f.read()
119
- image_base64 = base64.b64encode(image_bytes).decode("utf-8")
120
 
121
  payload = {
122
  "inputs": {
@@ -130,19 +131,18 @@ def detect(image_path):
130
  response = requests.post(
131
  url,
132
  json=payload,
133
- headers={
134
- "Authorization": f"Bearer {api_key}",
135
- "Content-Type": "application/json"
136
- },
137
  timeout=15
138
  )
139
 
 
 
 
140
  if response.status_code != 200:
141
  return f"❌ Roboflow Error: {response.text}"
142
 
143
  data = response.json()
144
 
145
- # extract predictions
146
  if "outputs" in data:
147
  return data["outputs"][0].get("predictions", [])
148
 
 
104
  # =====================
105
  import base64
106
 
107
+ import base64
108
+
109
  def detect(image_path):
110
  api_key = os.getenv("ROBOFLOW_API_KEY")
111
 
 
117
  try:
118
  # convert image → base64
119
  with open(image_path, "rb") as f:
120
+ image_base64 = base64.b64encode(f.read()).decode("utf-8")
 
121
 
122
  payload = {
123
  "inputs": {
 
131
  response = requests.post(
132
  url,
133
  json=payload,
134
+ params={"api_key": api_key}, # ✅ THIS FIXES 401
 
 
 
135
  timeout=15
136
  )
137
 
138
+ print("STATUS:", response.status_code)
139
+ print("RESPONSE:", response.text)
140
+
141
  if response.status_code != 200:
142
  return f"❌ Roboflow Error: {response.text}"
143
 
144
  data = response.json()
145
 
 
146
  if "outputs" in data:
147
  return data["outputs"][0].get("predictions", [])
148