Spaces:
Build error
Build error
Commit ·
e56d73c
1
Parent(s): 09a6458
update
Browse files31 unmodified lines3233343535363713 unmodified lines515253555455565 unmodified lines62636467656667716869707 unmodified lines787980818283848586879 unmodified lines97989910010110210310410410510610710810 unmodified lines11912012112112212312412512612712812913013113238 unmodified lines17117217316617417517630 unmodified lines20720820920321021121221312 unmodified lines22622722822222923023123222723323423523623723823924024124224324424524644 unmodified lines29129229327829429529631 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 lines logger.exception(f"Error loading samples from {dir_path}: {e}") return samples
# Randomly select balanced samplesdef select_balanced_samples(samples): try:5 unmodified lines logger.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 lines return "Missing username, seed, or method", 400
try: # Save the method to a file with 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 lines logger.info(f"Generated filename: {filename}")
# Save selected samples to a JSON file os.makedirs('session_data', exist_ok=True) with open(f'session_data/{filename}', 'w') as f: json.dump(selected_samples, f)
session['responses'] = [] # Initialize responses list session['method'] = method # Store the selected method session['username'] = username # Store the username for later use
return redirect(url_for('experiment', username=username, sample_index=0, seed=seed, filename=filename)) except Exception as e:10 unmodified lines with open(f'session_data/{filename}', 'r') as f: selected_samples = json.load(f)
method = session.get('method') # Retrieve the selected method # Read the method from the file method_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", 500
if sample_index >= len(selected_samples): logger.error(f"Sample index {sample_index} exceeds the number of selected samples {len(selected_samples)}.")38 unmodified lines logger.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.", 'Task': "Please make a decision to Accept/Reject the AI prediction based on the explanation.", 'User Feedback': feedback }
12 unmodified lines logger.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') username = session.get('username')
# Read the method from the file method_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 use else: logger.error("Method file not found.") return "Method file not found", 500
if method == "Chain-of-Table": json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'44 unmodified lines logger.exception(f"Error in completed route: {e}") return "An error occurred", 500
if __name__ == "__main__": os.makedirs('session_data', exist_ok=True) # Ensure the directory for session files exists app.run(host="0.0.0.0", port=7860)app.py+26-11