Spaces:
Sleeping
Sleeping
| from flask import Flask, render_template, request, redirect, url_for | |
| import pandas as pd | |
| import os | |
| app = Flask(__name__) | |
| # Load dữ liệu câu hỏi và câu trả lời từ CSV | |
| df = pd.read_csv('questions_answers.csv', encoding='utf-8', sep='|') | |
| def index(): | |
| return render_template('index.html', questions=df.to_dict(orient='records')) | |
| def vote(): | |
| # Danh sách để lưu các record vote của phiên hiện tại | |
| current_votes = [] | |
| # Nhận vote từ form | |
| for index, row in df.iterrows(): | |
| question = row['Câu hỏi'] | |
| # Lấy giá trị điểm từ 1 đến 5 cho từng mô hình | |
| rag_vote = request.form.get(f'RAG_{question}') | |
| gpt_vote = request.form.get(f'GPT_{question}') | |
| lexcentra_vote = request.form.get(f'lexcentra_{question}') | |
| ailuat_vote = request.form.get(f'ailuat_{question}') | |
| lawpress_vote = request.form.get(f'law&press_{question}') | |
| # Tạo record cho câu hỏi này | |
| vote_record = { | |
| 'Câu hỏi': index+1, | |
| 'RAG': int(rag_vote) if rag_vote else 0, | |
| 'GPT': int(gpt_vote) if gpt_vote else 0, | |
| 'lexcentra': int(lexcentra_vote) if lexcentra_vote else 0, | |
| 'ailuat': int(ailuat_vote) if ailuat_vote else 0, | |
| 'law&press': int(lawpress_vote) if lawpress_vote else 0 | |
| } | |
| current_votes.append(vote_record) | |
| # Lưu kết quả vote vào file CSV (append mode) | |
| results_df = pd.DataFrame(current_votes) | |
| # Kiểm tra xem file đã tồn tại chưa để quyết định ghi header | |
| file_exists = os.path.isfile('votes_results.csv') | |
| results_df.to_csv('votes_results.csv', mode='a', index=False, encoding='utf-8', sep='|', header=not file_exists) | |
| return redirect(url_for('thank_you')) | |
| def thank_you(): | |
| return "Cảm ơn bạn đã tham gia bỏ phiếu!" | |
| if __name__ == '__main__': | |
| app.run(debug=True) | |