Spaces:
Build error
Build error
Commit ·
6103c97
1
Parent(s): 497f14e
update
Browse files2 unmodified lines34566787 unmodified lines161718202119202174 unmodified lines969798102991001011021031041052 unmodified lines10810911011111211311411511611511711811912012112212312435 unmodified lines1601611621571581591601611621631641651661671681691701711631641654 unmodified lines17017117218217317417517617717817941 unmodified lines22122222322422522622721 unmodified lines24925025125725825225325425516 unmodified lines2722732742812822832842852862872882892902912922932942952962972982752762773012 unmodified linesimport randomimport osimport stringfrom flask_session import Sessionimport logging
# Set up logging7 unmodified lines
app = 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 lines
logger.info(f"Generated filename: {filename}")
session['selected_samples'] = selected_samples # Save selected samples to a JSON file 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
2 unmodified lines logger.exception(f"Error in index route: {e}") return "An error occurred", 500 return 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', [])
# Load selected samples from the JSON file with open(f'session_data/{filename}', 'r') as f: selected_samples = json.load(f)
method = session.get('method') # Retrieve the selected method
if sample_index >= len(selected_samples):35 unmodified lines return "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-SQLs visualization_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 lines sample_index = int(request.form['sample_index']) filename = request.form['filename']
selected_samples = session.get('selected_samples', []) # Load selected samples from the JSON file with open(f'session_data/{filename}', 'r') as f: selected_samples = json.load(f)
responses = session.get('responses', [])
responses.append({41 unmodified lines try: 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 lines 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(): if ground_truth_key in ground_truth and ground_truth[ground_truth_key]['answer'].upper() == feedback.upper(): correct_responses += 1 else: logger.warning(f"Missing or mismatched key: {ground_truth_key}")16 unmodified lines return "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__": 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+18-42