iacelectricals commited on
Commit
ee03ea6
·
verified ·
1 Parent(s): bd6209a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -9,6 +9,7 @@ HF_TOKEN = os.getenv("HF_API_KEY")
9
  # Authenticate with Google Sheets
10
  gc = gspread.service_account(filename="credentials.json")
11
  sheet = gc.open_by_url("https://docs.google.com/spreadsheets/d/1t4cVCDInque373CHEeMaNuwi8pGnAELqHJSPRLG3bKk/edit").worksheet("Items QR Code")
 
12
 
13
  # Token for Hugging Face Space
14
 
@@ -37,34 +38,32 @@ def get_item():
37
  else:
38
  return jsonify({"error": "Item not found in Hugging Face Space"}), 404
39
 
40
- if __name__ == '__main__':
41
- app.run(host='0.0.0.0', port=7860)
42
-
43
-
44
- # from flask import Flask, request, jsonify
45
- # import gspread
46
 
47
- # app = Flask(__name__)
 
 
 
 
 
48
 
49
- # # Authenticate with Google Sheets
50
- # gc = gspread.service_account(filename="credentials.json")
51
- # sheet = gc.open_by_url("https://docs.google.com/spreadsheets/d/11fLYMW3HSogJKrvawn6okMrau2JJ1FMToMVl2g0-ubU/edit").worksheet("Items QR Code")
 
 
 
52
 
53
- # @app.route('/items', methods=['GET'])
54
- # def get_item():
55
- # item_description = request.args.get('description')
56
- # print(item_description)
57
- # if not item_description:
58
- # return jsonify({"error": "Missing item description"}), 400
59
 
60
- # # Search for the item in the sheet
61
- # data = sheet.get_all_records()
62
- # for row in data:
63
- # if row["ItemDescription"] == item_description:
64
- # return jsonify(row)
65
- # print("result" + row)
66
-
67
- # return jsonify({"error": "Item not found"}), 404
68
 
69
- # if __name__ == '__main__':
70
- # app.run(host='0.0.0.0', port=7860)
 
 
9
  # Authenticate with Google Sheets
10
  gc = gspread.service_account(filename="credentials.json")
11
  sheet = gc.open_by_url("https://docs.google.com/spreadsheets/d/1t4cVCDInque373CHEeMaNuwi8pGnAELqHJSPRLG3bKk/edit").worksheet("Items QR Code")
12
+ sheetStore = gc.open_by_url("https://docs.google.com/spreadsheets/d/11fLYMW3HSogJKrvawn6okMrau2JJ1FMToMVl2g0-ubU/edit").worksheet("Items QR Code")
13
 
14
  # Token for Hugging Face Space
15
 
 
38
  else:
39
  return jsonify({"error": "Item not found in Hugging Face Space"}), 404
40
 
 
 
 
 
 
 
41
 
42
+ @app.route('/storeItems', methods=['GET'])
43
+ def get_item():
44
+ item_description = request.args.get('description')
45
+ print(item_description)
46
+ if not item_description:
47
+ return jsonify({"error": "Missing item description"}), 400
48
 
49
+ # Search for the item in the Google Sheet
50
+ data = sheet.get_all_records()
51
+ for row in data:
52
+ if row["ItemDescription"] == item_description:
53
+ return jsonify(row)
54
+ print("result" + row)
55
 
56
+ # If not found, proxy the request to Hugging Face Space
57
+ hf_response = requests.get(
58
+ f"https://iacelectricals-backendstoreitem.hf.space/items?description={item_description}",
59
+ headers={"Authorization": f"Bearer {HF_TOKEN}"}
60
+ )
 
61
 
62
+ if hf_response.status_code == 200:
63
+ return hf_response.json()
64
+ else:
65
+ return jsonify({"error": "Item not found in Hugging Face Space"}), 404
 
 
 
 
66
 
67
+
68
+ if __name__ == '__main__':
69
+ app.run(host='0.0.0.0', port=7860)