VyLala commited on
Commit
2bd304e
·
verified ·
1 Parent(s): 64ec7fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -2
app.py CHANGED
@@ -36,7 +36,7 @@ def compute_final_suggested_location(rows):
36
  import gspread
37
  from oauth2client.service_account import ServiceAccountCredentials
38
 
39
- creds_dict = json.loads(os.environ["GCP_CREDS_JSON"])
40
 
41
  scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
42
  creds = ServiceAccountCredentials.from_json_keyfile_dict(creds_dict, scope)
@@ -56,7 +56,34 @@ def store_feedback_to_google_sheets(accession, answer1, answer2, contact=""):
56
  sheet.append_row([accession, answer1, answer2, contact])
57
  return "✅ Feedback submitted. Thank you!"
58
  except Exception as e:
59
- return f"❌ Error submitting feedback: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  def summarize_results(accession):
62
  try:
 
36
  import gspread
37
  from oauth2client.service_account import ServiceAccountCredentials
38
 
39
+ '''creds_dict = json.loads(os.environ["GCP_CREDS_JSON"])
40
 
41
  scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
42
  creds = ServiceAccountCredentials.from_json_keyfile_dict(creds_dict, scope)
 
56
  sheet.append_row([accession, answer1, answer2, contact])
57
  return "✅ Feedback submitted. Thank you!"
58
  except Exception as e:
59
+ return f"❌ Error submitting feedback: {str(e)}"'''
60
+
61
+ import os
62
+ import json
63
+ from oauth2client.service_account import ServiceAccountCredentials
64
+ import gspread
65
+
66
+ def store_feedback_to_google_sheet(accession, answer1, answer2, contact=""):
67
+ if not answer1.strip() or not answer2.strip():
68
+ return "⚠️ Please answer both questions before submitting."
69
+
70
+ try:
71
+ # ✅ Step: Load credentials from Hugging Face secret
72
+ creds_dict = json.loads(os.environ["GCP_CREDS_JSON"])
73
+ scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
74
+ creds = ServiceAccountCredentials.from_json_keyfile_dict(creds_dict, scope)
75
+
76
+ # Connect to Google Sheet
77
+ client = gspread.authorize(creds)
78
+ sheet = client.open("feedback_mtdna").sheet1 # make sure sheet name matches
79
+
80
+ # Append feedback
81
+ sheet.append_row([accession, answer1, answer2, contact])
82
+ return "✅ Feedback submitted. Thank you!"
83
+
84
+ except Exception as e:
85
+ return f"❌ Error submitting feedback: {e}"
86
+
87
 
88
  def summarize_results(accession):
89
  try: