VyLala commited on
Commit
bfbba22
·
verified ·
1 Parent(s): 3bc11e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -32,20 +32,25 @@ def compute_final_suggested_location(rows):
32
  return counts, (top_location, count)
33
 
34
  # Store feedback (with required fields)
35
- def store_feedback_to_drive(accession, answer1, answer2, contact=""):
 
 
 
36
  if not answer1.strip() or not answer2.strip():
37
  return "⚠️ Please answer both questions before submitting."
38
 
39
- feedback_file = "data/user_fb/feedback_mtdna.csv"
40
- header = ["accession", "helpful", "improvement", "contact"]
41
- row = [accession, answer1, answer2, contact]
42
- file_exists = os.path.isfile(feedback_file)
43
- with open(feedback_file, "a", newline="") as f:
44
- writer = csv.writer(f)
45
- #if not file_exists:
46
- writer.writerow(header)
47
- writer.writerow(row)
48
- return "✅ Feedback submitted. Thank you!"
 
 
49
 
50
  def summarize_results(accession):
51
  try:
@@ -128,7 +133,7 @@ with gr.Blocks() as interface:
128
 
129
  run_button.click(fn=classify_with_loading, inputs=accession, outputs=status)
130
  run_button.click(fn=classify_main, inputs=accession, outputs=[output_table, output_summary, status])
131
- submit_feedback.click(fn=store_feedback_to_drive, inputs=[accession, q1, q2, contact], outputs=feedback_status)
132
  reset_button.click(fn=reset_fields, inputs=[], outputs=[accession, q1, q2, contact, feedback_status, output_table, output_summary, status])
133
 
134
  interface.launch(share=True)
 
32
  return counts, (top_location, count)
33
 
34
  # Store feedback (with required fields)
35
+ import gspread
36
+ from oauth2client.service_account import ServiceAccountCredentials
37
+
38
+ def store_feedback_to_google_sheets(accession, answer1, answer2, contact=""):
39
  if not answer1.strip() or not answer2.strip():
40
  return "⚠️ Please answer both questions before submitting."
41
 
42
+ try:
43
+ # Define the scope and authenticate
44
+ scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
45
+ creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)
46
+ client = gspread.authorize(creds)
47
+
48
+ # Open the spreadsheet and worksheet
49
+ sheet = client.open("feedback_mtdna").sheet1 # You can change the name
50
+ sheet.append_row([accession, answer1, answer2, contact])
51
+ return "✅ Feedback submitted. Thank you!"
52
+ except Exception as e:
53
+ return f"❌ Error submitting feedback: {str(e)}"
54
 
55
  def summarize_results(accession):
56
  try:
 
133
 
134
  run_button.click(fn=classify_with_loading, inputs=accession, outputs=status)
135
  run_button.click(fn=classify_main, inputs=accession, outputs=[output_table, output_summary, status])
136
+ submit_feedback.click(fn=store_feedback_to_google_sheets, inputs=[accession, q1, q2, contact], outputs=feedback_status)
137
  reset_button.click(fn=reset_fields, inputs=[], outputs=[accession, q1, q2, contact, feedback_status, output_table, output_summary, status])
138
 
139
  interface.launch(share=True)