Spaces:
Build error
Build error
Commit ·
4faaa69
1
Parent(s): abf035a
update
Browse filesFiles changed (3)
- app.py+38-44
- templates/completed.html+6-54
- templates/experiment.html+4-76
100 unmodified lines10110210310410510610710810911011111211311411511611711811912012122 unmodified lines14414514614714814915011 unmodified lines1621631641651661671681691701711721731743 unmodified lines1781791801811821831841851861871889 unmodified lines1981992002012022032042052062072082092102112122132141 unmodified line2162172182192202212223 unmodified lines2262272282292302315 unmodified lines237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288100 unmodified linesdef 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.")if request.method == 'POST':username = request.form.get('username')seed = request.form.get('seed')method = request.form.get('method')if not username or not seed or not method:logger.error("Missing username, seed, or method.")return "Missing username, seed, or method", 400try:seed = int(seed)random.seed(seed)all_samples = load_samples(method)selected_samples = select_balanced_samples(all_samples)logger.info(f"Number of selected samples: {len(selected_samples)}")22 unmodified lineslogger.exception(f"Error in index route: {e}")return "An error occurred", 500return render_template('index.html')@app.route('/experiment/<username>', methods=['GET', 'POST'])def experiment(username):try:11 unmodified linesvisualization_file = selected_samples[current_index]if method == "Chain-of-Table":vis_dir = 'htmls_COT'else:vis_dir = 'htmls_POS'# Determine the correct visualization directory based on the categoryfor category, dir_path in (VISUALIZATION_DIRS_CHAIN_OF_TABLE if method == "Chain-of-Table" else VISUALIZATION_DIRS_PLAN_OF_SQLS).items():if visualization_file in os.listdir(dir_path):visualization_path = os.path.join(vis_dir, category, visualization_file)break3 unmodified lineslogger.info(f"Rendering experiment page with visualization: {visualization_path}")# statement = "Please make a decision to Accept/Reject the AI prediction based on the explanation."statement = """A Table Question Answering model is working on Table Fact Verification task (TabFact dataset), verifying if a given Statement is TRUE or FALSE on a given input Table.You are given an explanation that describes the reasoning process of the Table QA model.Please carefully analyze the explanation and determine whether you should Accept or Reject the AI prediction."""return render_template('experiment.html',9 unmodified linesdef feedback():try:username = request.form['username']feedback = request.form['feedback']session_data = load_session_data(username)if not session_data:logger.error(f"No session data found for user: {username}")return redirect(url_for('index'))# Store the feedbacksession_data['responses'].append({'sample_id': session_data['current_index'],'feedback': feedback})# Move to the next sample1 unmodified line# Save updated session datasave_session_data(username, session_data)logger.info(f"Feedback saved for user {username}, sample {session_data['current_index'] - 1}")if session_data['current_index'] >= len(session_data['selected_samples']):return redirect(url_for('completed', username=username))3 unmodified lineslogger.exception(f"Error in feedback route: {e}")return "An error occurred", 500@app.route('/completed/<username>')def completed(username):try:5 unmodified linesresponses = session_data['responses']method = session_data['method']if method == "Chain-of-Table":json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'else: # Default to Plan-of-SQLsjson_file = 'Tabular_LLMs_human_study_vis_6_POS.json'with open(json_file, 'r') as f:ground_truth = json.load(f)correct_responses = 0accept_count = 0reject_count = 0for response in responses:sample_id = response['sample_id']feedback = response['feedback']visualization_file = session_data['selected_samples'][sample_id]index = visualization_file.split('-')[1].split('.')[0] # Extract index from filenameif feedback.upper() == "TRUE":accept_count += 1elif feedback.upper() == "FALSE":reject_count += 1if method == "Chain-of-Table":ground_truth_key = f"COT_test-{index}.html"else:ground_truth_key = f"POS_test-{index}.html"if ground_truth_key in ground_truth and ground_truth[ground_truth_key]['answer'].upper() == feedback.upper():correct_responses += 1else:logger.warning(f"Missing or mismatched key: {ground_truth_key}")accuracy = (correct_responses / len(responses)) * 100 if responses else 0accuracy = round(accuracy, 2)accept_percentage = (accept_count / len(responses)) * 100 if len(responses) else 0reject_percentage = (reject_count / len(responses)) * 100 if len(responses) else 0accept_percentage = round(accept_percentage, 2)reject_percentage = round(reject_percentage, 2)return render_template('completed.html',accuracy=accuracy,accept_percentage=accept_percentage,reject_percentage=reject_percentage)except Exception as e:logger.exception(f"An error occurred in the completed route: {e}")return "An error occurred", 500100 unmodified lines10110210310410510610710810911011111211311411511611711811912012112212312422 unmodified lines14714814915015115211 unmodified lines1641651661671681691701711721733 unmodified lines1771781791801811821831841859 unmodified lines1951961971981992002012022032042052062072082092102111 unmodified line2132142152162172182193 unmodified lines2232242252262272282295 unmodified lines235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282100 unmodified linesdef 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.")if request.method == 'POST':username = request.form.get('username')seed = request.form.get('seed')if not username or not seed:logger.error("Missing username or seed.")return "Missing username or seed", 400try:seed = int(seed)random.seed(seed)# Use only one method (e.g., "Chain-of-Table")method = "Chain-of-Table"all_samples = load_samples(method)selected_samples = select_balanced_samples(all_samples)logger.info(f"Number of selected samples: {len(selected_samples)}")22 unmodified lineslogger.exception(f"Error in index route: {e}")return "An error occurred", 500return render_template('index.html')@app.route('/experiment/<username>', methods=['GET', 'POST'])def experiment(username):try:11 unmodified linesvisualization_file = selected_samples[current_index]vis_dir = 'htmls_COT' if method == "Chain-of-Table" else 'htmls_POS'# Determine the correct visualization directory based on the categoryfor category, dir_path in VISUALIZATION_DIRS_CHAIN_OF_TABLE.items():if visualization_file in os.listdir(dir_path):visualization_path = os.path.join(vis_dir, category, visualization_file)break3 unmodified lineslogger.info(f"Rendering experiment page with visualization: {visualization_path}")statement = """Based on the explanation provided, what do you think the AI model will predict?Will it predict the statement as TRUE or FALSE?"""return render_template('experiment.html',9 unmodified linesdef feedback():try:username = request.form['username']prediction = request.form['prediction']session_data = load_session_data(username)if not session_data:logger.error(f"No session data found for user: {username}")return redirect(url_for('index'))# Store the user's predictionsession_data['responses'].append({'sample_id': session_data['current_index'],'user_prediction': prediction})# Move to the next sample1 unmodified line# Save updated session datasave_session_data(username, session_data)logger.info(f"Prediction saved for user {username}, sample {session_data['current_index'] - 1}")if session_data['current_index'] >= len(session_data['selected_samples']):return redirect(url_for('completed', username=username))3 unmodified lineslogger.exception(f"Error in feedback route: {e}")return "An error occurred", 500@app.route('/completed/<username>')def completed(username):try:5 unmodified linesresponses = session_data['responses']method = session_data['method']json_file = 'Tabular_LLMs_human_study_vis_6_COT.json' if method == "Chain-of-Table" else 'Tabular_LLMs_human_study_vis_6_POS.json'with open(json_file, 'r') as f:ground_truth = json.load(f)correct_predictions = 0true_predictions = 0false_predictions = 0for response in responses:sample_id = response['sample_id']user_prediction = response['user_prediction']visualization_file = session_data['selected_samples'][sample_id]index = visualization_file.split('-')[1].split('.')[0] # Extract index from filenameground_truth_key = f"COT_test-{index}.html" if method == "Chain-of-Table" else f"POS_test-{index}.html"if ground_truth_key in ground_truth:model_prediction = ground_truth[ground_truth_key]['answer'].upper()if user_prediction.upper() == model_prediction:correct_predictions += 1if user_prediction.upper() == "TRUE":true_predictions += 1elif user_prediction.upper() == "FALSE":false_predictions += 1else:logger.warning(f"Missing key in ground truth: {ground_truth_key}")accuracy = (correct_predictions / len(responses)) * 100 if responses else 0accuracy = round(accuracy, 2)true_percentage = (true_predictions / len(responses)) * 100 if len(responses) else 0false_percentage = (false_predictions / len(responses)) * 100 if len(responses) else 0true_percentage = round(true_percentage, 2)false_percentage = round(false_percentage, 2)return render_template('completed.html',accuracy=accuracy,true_percentage=true_percentage,false_percentage=false_percentage)except Exception as e:logger.exception(f"An error occurred in the completed route: {e}")return "An error occurred", 500
2 unmodified lines34567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465661 unmodified line686970712 unmodified lines<head><title>Experiment Completed</title><style>body {font-family: 'Roboto', sans-serif;background: url('/static/images/background.jpg') no-repeat center center fixed;background-size: cover;display: flex;justify-content: center;align-items: center;height: 100vh;margin: 0;}.container {text-align: center;background-color: #ffffff; /* Solid background color */padding: 60px;border-radius: 10px;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);width: 60%;}h1 {color: #000000; /* Black text color */font-size: 48px; /* Larger text */margin-bottom: 30px;}p {color: #000000; /* Black text color */font-size: 24px; /* Larger text */margin-bottom: 30px;}.thank-you {color: #4CAF50;font-size: 24px; /* Larger text */margin-top: 20px;}.button-container {margin-top: 30px;}button {background-color: #4CAF50;color: white;padding: 15px 30px;border: none;border-radius: 5px;cursor: pointer;font-size: 24px; /* Larger text */transition: background-color 0.3s ease;}button:hover {background-color: #45a049;}</style></head><body><div class="container"><h1>Thank you! 😃😃😃</h1><p>Experiment completed! Your responses have been recorded.</p><p>Accuracy: {{ accuracy }}%</p><p>Accepted: {{ accept_percentage }}%</p><p>Rejected: {{ reject_percentage }}%</p><div class="button-container"><a href="/" style="text-decoration: none;"><button>Back to Start Page</button>1 unmodified line</div></div></body></html>2 unmodified lines34567891011121314151617181 unmodified line202122232 unmodified lines<head><title>Experiment Completed</title><style>/* ... (keep existing styles) ... */</style></head><body><div class="container"><h1>Thank you! 😃😃😃</h1><p>Experiment completed! Your predictions have been recorded.</p><p>Prediction Accuracy: {{ accuracy }}%</p><p>Predicted TRUE: {{ true_percentage }}%</p><p>Predicted FALSE: {{ false_percentage }}%</p><div class="button-container"><a href="/" style="text-decoration: none;"><button>Back to Start Page</button>1 unmodified line</div></div></body></html>
2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384856 unmodified lines92939495969798991001011022 unmodified lines<head><title>Experiment</title><style>body {font-family: 'Roboto', sans-serif;background: url('/static/images/background.jpg') no-repeat center center fixed;background-size: cover;margin: 0;padding: 0;display: flex;justify-content: center;align-items: center;height: 100vh;}.container {background-color: #ffffff; /* Solid background color */padding: 20px;border-radius: 10px;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);width: 100%;height: 100%;margin: 0;text-align: center;display: flex;flex-direction: column;}h1, h2 {color: #000000; /* Black text color */font-size: 24px; /* Smaller text */}p {color: #000000; /* Black text color */font-size: 18px; /* Smaller text */}.visualization-container {flex: 1;margin: 20px 0;}.buttons {display: flex;justify-content: space-between;}button {background-color: #4CAF50;color: white;padding: 15px 30px;border: none;border-radius: 5px;cursor: pointer;font-size: 18px; /* Smaller text */margin-top: 20px;width: 48%;transition: background-color 0.3s ease;}button:hover {background-color: #45a049;}button.reject {background-color: #f44336;}button.reject:hover {background-color: #e53935;}iframe {width: 100%;height: calc(100vh - 150px); /* Adjust height to fit the screen */border: none;}</style><link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"><script>window.onload = function() {var iframe = document.querySelector('iframe');iframe.onload = function() {var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;var style = document.createElement('style');style.innerHTML = 'body { font-size: 14px; }'; /* Adjust this value as needed */iframeDocument.head.appendChild(style);};};</script></head><body>6 unmodified lines<div class="buttons"><form action="{{ url_for('feedback') }}" method="post" style="width: 48%;"><input type="hidden" name="username" value="{{ username }}"><button type="submit" name="feedback" value="TRUE">Accept</button></form><form action="{{ url_for('feedback') }}" method="post" style="width: 48%;"><input type="hidden" name="username" value="{{ username }}"><button type="submit" name="feedback" value="FALSE" class="reject">Reject</button></form></div></div>2 unmodified lines3456789101112136 unmodified lines20212223242526272829302 unmodified lines<head><title>Experiment</title><style>/* ... (keep existing styles) ... */</style><link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet"><script>// ... (keep existing script) ...</script></head><body>6 unmodified lines<div class="buttons"><form action="{{ url_for('feedback') }}" method="post" style="width: 48%;"><input type="hidden" name="username" value="{{ username }}"><button type="submit" name="prediction" value="TRUE">Predict TRUE</button></form><form action="{{ url_for('feedback') }}" method="post" style="width: 48%;"><input type="hidden" name="username" value="{{ username }}"><button type="submit" name="prediction" value="FALSE" class="reject">Predict FALSE</button></form></div></div>
app.py+38-44
templates/completed.html+6-54
templates/experiment.html+4-76