Hachem commited on
Commit
b38ae2b
·
verified ·
1 Parent(s): 64c8f4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -72,16 +72,16 @@ def get_product_info(barcode):
72
  fallback_api_key = "0aj97xf02hji3h4wep2tlkldc98zf2"
73
  primary_url = f"https://api.upcdatabase.org/product/{barcode}?apikey={primary_api_key}"
74
  fallback_url = f"https://api.barcodelookup.com/v3/products?barcode={barcode}&formatted=y&key={fallback_api_key}"
75
-
76
  try:
77
  response = requests.get(primary_url)
78
- if response.status_code == 200 and response.json().get('valid', False):
79
- return (response.json(),1)
 
80
  else:
81
  response = requests.get(fallback_url)
82
- return (response.json(),2) if response.status_code == 200 else None
83
- except requests.RequestException as e:
84
- return (False,False)
85
 
86
 
87
 
@@ -103,7 +103,6 @@ def process_image(image):
103
  barcode = read_barcode(image)
104
  if barcode:
105
  product_info,API = get_product_info(barcode)
106
- print(barcode)
107
  if product_info:
108
  if barcode=="0887276371375":
109
  energy_info = {
@@ -157,9 +156,6 @@ def process_image(image):
157
  return barcode, "Product information not found", "{}"
158
  else:
159
  predicted_class_index,predicted_class_name,tips_text=predict_image(image)
160
- print(predicted_class_index)
161
- print(predicted_class_name)
162
- print(tips_text)
163
  data = {"tips": tips_text}
164
  json_data = json.dumps(data, indent=4)
165
 
 
72
  fallback_api_key = "0aj97xf02hji3h4wep2tlkldc98zf2"
73
  primary_url = f"https://api.upcdatabase.org/product/{barcode}?apikey={primary_api_key}"
74
  fallback_url = f"https://api.barcodelookup.com/v3/products?barcode={barcode}&formatted=y&key={fallback_api_key}"
 
75
  try:
76
  response = requests.get(primary_url)
77
+ data=response.json()
78
+ if response.status_code == 200 and data['success']:
79
+ return (data,1)
80
  else:
81
  response = requests.get(fallback_url)
82
+ return (response.json(),2)
83
+ except:
84
+ return ({},0)
85
 
86
 
87
 
 
103
  barcode = read_barcode(image)
104
  if barcode:
105
  product_info,API = get_product_info(barcode)
 
106
  if product_info:
107
  if barcode=="0887276371375":
108
  energy_info = {
 
156
  return barcode, "Product information not found", "{}"
157
  else:
158
  predicted_class_index,predicted_class_name,tips_text=predict_image(image)
 
 
 
159
  data = {"tips": tips_text}
160
  json_data = json.dumps(data, indent=4)
161