Spaces:
Build error
Build error
Commit ·
e56d73c
1
Parent(s): 09a6458
update
Browse files31 unmodified lines3233343536373813 unmodified lines525354555657585 unmodified lines64656667686970717273747 unmodified lines8283848586879 unmodified lines97989910010110210310410510610710 unmodified lines11811912012112212312438 unmodified lines16316416516616716816930 unmodified lines20020120220320420520612 unmodified lines21922022122222322422522622722822923044 unmodified lines27527627727827928028131 unmodified lines"FN": "htmls_COT/FN"}# Load all sample files from the directories based on the selected methoddef load_samples(method):logger.info(f"Loading samples for method: {method}")13 unmodified lineslogger.exception(f"Error loading samples from {dir_path}: {e}")return samples# Randomly select balanced samplesdef select_balanced_samples(samples):try:5 unmodified lineslogger.exception("Error selecting balanced samples")return []def generate_random_string(length=8):return ''.join(random.choices(string.ascii_letters + string.digits, k=length))@app.route('/', methods=['GET', 'POST'])def index():logger.info("Rendering index page.")7 unmodified linesreturn "Missing username, seed, or method", 400try:seed = int(seed)random.seed(seed)all_samples = load_samples(method)9 unmodified lineslogger.info(f"Generated filename: {filename}")# Save selected samples to a JSON filewith open(f'session_data/{filename}', 'w') as f:json.dump(selected_samples, f)session['responses'] = [] # Initialize responses listsession['method'] = method # Store the selected methodreturn redirect(url_for('experiment', username=username, sample_index=0, seed=seed, filename=filename))except Exception as e:10 unmodified lineswith open(f'session_data/{filename}', 'r') as f:selected_samples = json.load(f)method = session.get('method') # Retrieve the selected methodif sample_index >= len(selected_samples):logger.error(f"Sample index {sample_index} exceeds the number of selected samples {len(selected_samples)}.")38 unmodified lineslogger.exception(f"An error occurred in the experiment route: {e}")return "An error occurred", 500@app.route('/feedback', methods=['POST'])def feedback():try:30 unmodified lines'Username': username,'Seed': seed,'Sample ID': sample_id,'Task': f"Please make a decision to Accept/Reject the AI prediction based on the explanation.",'User Feedback': feedback}12 unmodified lineslogger.exception(f"Error in feedback route: {e}")return "An error occurred", 500@app.route('/completed/<filename>')def completed(filename):try:responses = session.get('responses', [])method = session.get('method')if method == "Chain-of-Table":json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'44 unmodified lineslogger.exception(f"Error in completed route: {e}")return "An error occurred", 500if __name__ == "__main__":os.makedirs('session_data', exist_ok=True) # Ensure the directory for session files existsapp.run(host="0.0.0.0", port=7860)31 unmodified lines32333435363713 unmodified lines5152535455565 unmodified lines6263646566676869707 unmodified lines787980818283848586879 unmodified lines97989910010110210310410510610710810 unmodified lines11912012112212312412512612712812913013113238 unmodified lines17117217317417517630 unmodified lines20720820921021121221312 unmodified lines22622722822923023123223323423523623723823924024124224324424524644 unmodified lines29129229329429529631 unmodified lines"FN": "htmls_COT/FN"}# Load all sample files from the directories based on the selected methoddef load_samples(method):logger.info(f"Loading samples for method: {method}")13 unmodified lineslogger.exception(f"Error loading samples from {dir_path}: {e}")return samples# Randomly select balanced samplesdef select_balanced_samples(samples):try:5 unmodified lineslogger.exception("Error selecting balanced samples")return []def generate_random_string(length=8):return ''.join(random.choices(string.ascii_letters + string.digits, k=length))@app.route('/', methods=['GET', 'POST'])def index():logger.info("Rendering index page.")7 unmodified linesreturn "Missing username, seed, or method", 400try:# Save the method to a filewith open(f'session_data/method_{username}.txt', 'w') as f:f.write(method)seed = int(seed)random.seed(seed)all_samples = load_samples(method)9 unmodified lineslogger.info(f"Generated filename: {filename}")# Save selected samples to a JSON fileos.makedirs('session_data', exist_ok=True)with open(f'session_data/{filename}', 'w') as f:json.dump(selected_samples, f)session['responses'] = [] # Initialize responses listsession['username'] = username # Store the username for later usereturn redirect(url_for('experiment', username=username, sample_index=0, seed=seed, filename=filename))except Exception as e:10 unmodified lineswith open(f'session_data/{filename}', 'r') as f:selected_samples = json.load(f)# Read the method from the filemethod_file_path = f'session_data/method_{username}.txt'if os.path.exists(method_file_path):with open(method_file_path, 'r') as f:method = f.read().strip()else:logger.error(f"Method file not found for user {username}.")return "Method file not found", 500if sample_index >= len(selected_samples):logger.error(f"Sample index {sample_index} exceeds the number of selected samples {len(selected_samples)}.")38 unmodified lineslogger.exception(f"An error occurred in the experiment route: {e}")return "An error occurred", 500@app.route('/feedback', methods=['POST'])def feedback():try:30 unmodified lines'Username': username,'Seed': seed,'Sample ID': sample_id,'Task': "Please make a decision to Accept/Reject the AI prediction based on the explanation.",'User Feedback': feedback}12 unmodified lineslogger.exception(f"Error in feedback route: {e}")return "An error occurred", 500@app.route('/completed/<filename>')def completed(filename):try:responses = session.get('responses', [])username = session.get('username')# Read the method from the filemethod_file_path = f'session_data/method_{username}.txt'if os.path.exists(method_file_path):with open(method_file_path, 'r') as f:method = f.read().strip()os.remove(method_file_path) # Remove the method file after useelse:logger.error("Method file not found.")return "Method file not found", 500if method == "Chain-of-Table":json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'44 unmodified lineslogger.exception(f"Error in completed route: {e}")return "An error occurred", 500if __name__ == "__main__":os.makedirs('session_data', exist_ok=True) # Ensure the directory for session files existsapp.run(host="0.0.0.0", port=7860)
app.py+26-11