Spaces:
Build error
Build error
Commit ·
6103c97
1
Parent(s): 497f14e
update
Browse files2 unmodified lines34567897 unmodified lines171819202122232474 unmodified lines991001011021031041052 unmodified lines10810911011111211311411511611711835 unmodified lines1541551561571581591601611621631641651661671681691701711721731744 unmodified lines17918018118218318418541 unmodified lines22722822923023123221 unmodified lines25425525625725825926026116 unmodified lines2782792802812822832842852862872882892902912922932942952962972982993003012 unmodified linesimport randomimport osimport stringfrom flask_session import Sessionimport logging# Set up logging7 unmodified linesapp = Flask(__name__)app.config['SECRET_KEY'] = 'supersecretkey' # Change this to a random secret keyapp.config['SESSION_TYPE'] = 'redis'Session(app)# Directories for visualizationsVISUALIZATION_DIRS_PLAN_OF_SQLS = {74 unmodified lineslogger.info(f"Generated filename: {filename}")session['selected_samples'] = selected_samplessession['responses'] = [] # Initialize responses listsession['method'] = method # Store the selected method2 unmodified lineslogger.exception(f"Error in index route: {e}")return "An error occurred", 500return render_template('index.html')@app.route('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])def experiment(username, sample_index, seed, filename):try:sample_index = int(sample_index)selected_samples = session.get('selected_samples', [])method = session.get('method') # Retrieve the selected methodif sample_index >= len(selected_samples):35 unmodified linesreturn "An error occurred", 500@app.route('/visualizations/<path:path>')def send_visualization(path):try:method = session.get('method')if method == "Chain-of-Table":visualization_dir = 'htmls_COT'else: # Default to Plan-of-SQLsvisualization_dir = 'visualizations'return send_from_directory(visualization_dir, path)except Exception as e:logger.exception(f"Error sending visualization: {e}")return "An error occurred", 500@app.route('/feedback', methods=['POST'])def feedback():try:4 unmodified linessample_index = int(request.form['sample_index'])filename = request.form['filename']selected_samples = session.get('selected_samples', [])responses = session.get('responses', [])responses.append({41 unmodified linestry:responses = session.get('responses', [])method = session.get('method')if method == "Chain-of-Table":json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'else: # Default to Plan-of-SQLs21 unmodified lineselse: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}")16 unmodified linesreturn "An error occurred", 500# if __name__ == '__main__':# try:# app.run(debug=False, port=7860)# except Exception as e:# logger.exception(f"Failed to start app: {e}")# from flask import Flask## app = Flask(__name__)## @app.route('/')# def index():# return "Hello, world!"# if __name__ == '__main__':# app.run(debug=False, port=7860)if __name__ == "__main__":app.run(host="0.0.0.0", port=7860)2 unmodified lines3456787 unmodified lines16171819202174 unmodified lines969798991001011021031041052 unmodified lines10810911011111211311411511611711811912012112212312435 unmodified lines1601611621631641654 unmodified lines17017117217317417517617717817941 unmodified lines22122222322422522622721 unmodified lines24925025125225325425516 unmodified lines2722732742752762772 unmodified linesimport randomimport osimport stringimport logging# Set up logging7 unmodified linesapp = Flask(__name__)app.config['SECRET_KEY'] = 'supersecretkey' # Change this to a random secret key# Directories for visualizationsVISUALIZATION_DIRS_PLAN_OF_SQLS = {74 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 method2 unmodified lineslogger.exception(f"Error in index route: {e}")return "An error occurred", 500return render_template('index.html')@app.route('/experiment/<username>/<sample_index>/<seed>/<filename>', methods=['GET'])def experiment(username, sample_index, seed, filename):try:sample_index = int(sample_index)# Load selected samples from the JSON filewith 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):35 unmodified linesreturn "An error occurred", 500@app.route('/feedback', methods=['POST'])def feedback():try:4 unmodified linessample_index = int(request.form['sample_index'])filename = request.form['filename']# Load selected samples from the JSON filewith open(f'session_data/{filename}', 'r') as f:selected_samples = json.load(f)responses = session.get('responses', [])responses.append({41 unmodified linestry:responses = session.get('responses', [])method = session.get('method')if method == "Chain-of-Table":json_file = 'Tabular_LLMs_human_study_vis_6_COT.json'else: # Default to Plan-of-SQLs21 unmodified lineselse: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}")16 unmodified linesreturn "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+18-42