Spaces:
Sleeping
Sleeping
Update app.py
Browse files41 unmodified lines424344454647481 unmodified line5051525354555657585960616263646553666768692 unmodified lines727374757677787980818283848541 unmodified lines client = gspread.authorize(creds) return client
# ===== Save to Google Sheets =====# ===== Save to Google Sheets =====# ===== Save to Google Sheets =====def save_to_gsheet(name, student_id, major, prediction, sheet_name="Trang tính1"):1 unmodified line now = datetime.now() current_time = now.strftime("%Y-%m-%d %H:%M:%S") # Convert prediction to the proper result in Vietnamese if isinstance(prediction, np.ndarray): prediction = prediction.tolist() # Convert ndarray to list else: prediction = str(prediction) # Ensure it's a string if it's not a list # Convert prediction to "Đúng hạn" or "Không đúng hạn" if prediction == 1: prediction_result = "Đúng hạn" else: prediction_result = "Không đúng hạn"
# Create a data row to insert into the sheet data_row = [name, student_id, major, prediction, current_time] data_row = [name, student_id, major, prediction_result, current_time]
# Connect to Google Sheets client = get_gsheet_client()2 unmodified lines sheet_id = "1i7bDNvLVLXN93_e-FN0JLzpg1jb64Z_aEuyPjIfwbdQ" # Use your actual ID here sheet = client.open_by_key(sheet_id).worksheet(sheet_name)
# Check if columns are set, if not, add them as headers if not sheet.get_all_values(): # If the sheet is empty sheet.append_row(["STT", "Họ và tên", "MSV", "Khoa", "Dự báo", "Thời gian"]) # Create headers # Append data to the sheet sheet.append_row(data_row)
# ===== List all sheet names =====# def list_sheet_names(sheet_id):# client = get_gsheet_client()app.py+19-1