Spaces:
Sleeping
Sleeping
Update app.py
Browse files71 unmodified lines7273747575767879777879808182838482838485868715 unmodified lines10310410510610610710847 unmodified lines15615715816016116215916016171 unmodified lines fallback_api_key = "0aj97xf02hji3h4wep2tlkldc98zf2" primary_url = f"https://api.upcdatabase.org/product/{barcode}?apikey={primary_api_key}" fallback_url = f"https://api.barcodelookup.com/v3/products?barcode={barcode}&formatted=y&key={fallback_api_key}" try: response = requests.get(primary_url) if response.status_code == 200 and response.json().get('valid', False): return (response.json(),1) data=response.json() if response.status_code == 200 and data['success']: return (data,1) else: response = requests.get(fallback_url) return (response.json(),2) if response.status_code == 200 else None except requests.RequestException as e: return (False,False) return (response.json(),2) except: return ({},0)
15 unmodified lines barcode = read_barcode(image) if barcode: product_info,API = get_product_info(barcode) print(barcode) if product_info: if barcode=="0887276371375": energy_info = {47 unmodified lines return barcode, "Product information not found", "{}" else: predicted_class_index,predicted_class_name,tips_text=predict_image(image) print(predicted_class_index) print(predicted_class_name) print(tips_text) data = {"tips": tips_text} json_data = json.dumps(data, indent=4) app.py+6-10