File size: 5,392 Bytes
215d189
146b688
40c29ba
215d189
 
 
 
146b688
ea2d6ae
215d189
 
b14be2c
215d189
 
 
40c29ba
ea2d6ae
146b688
 
b845998
146b688
f7e9cda
 
 
40c29ba
1047c44
40c29ba
 
ca60da9
40c29ba
 
 
 
 
 
 
 
 
 
ca60da9
 
40c29ba
 
 
 
 
 
 
 
 
b845998
40c29ba
1047c44
 
146b688
 
40c29ba
b14be2c
b845998
 
1047c44
d7c0630
1047c44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7c0630
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b845998
b42419d
 
 
 
215d189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea2d6ae
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import os
import pandas as pd
import utils
import base64
from flask import Flask, render_template, request, redirect, url_for
from postmarker.core import PostmarkClient
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads'  # Directory where files will be stored
app.config['ALLOWED_EXTENSIONS'] = {'zip'}

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in app.config['ALLOWED_EXTENSIONS']

@app.route('/')
def index():
    # Load the CSV file into a DataFrame
    df = pd.read_csv('static/leaderboard.csv')

    df = df.round(3)
    df.insert(0, '#', '')

    up_arrow, down_arrow = "↑", "↓"
    # up_arrow, down_arrow = "⬆️", "⬇️"
    # up_arrow, down_arrow = "▲", "▼"

    df = df.rename(columns={
        "Ordinal (Win rate)": f"Ordinal - Win rate ({up_arrow})",
        "Cardinal (Score)": f"Cardinal - Score ({up_arrow})",
        "RO Stability": f"RO Stability ({up_arrow})",
        "Stress": f"Stress ({down_arrow})",
        "Rank Distance": f"Rank Distance ({down_arrow})",
        "Separability": f"Separability ({up_arrow})",
        "CFI": f"CFI ({up_arrow})",
        "SRMR": f"SRMR ({down_arrow})",
        "RMSEA": f"RMSEA ({down_arrow})",
        "Cronbach alpha": f"Cronbach alpha ({up_arrow})"
    })

    # Generate full table HTML with clickable model names
    ################
    main_table_metrics = [
        "#",
        "Model",
        f"Ordinal - Win rate ({up_arrow})",
        f"Cardinal - Score ({up_arrow})",
        f"RO Stability ({up_arrow})"
    ]

    main_df = df[main_table_metrics].copy()
    main_table_html = utils.metrics_df_to_table_html(main_df, additional_class="main-table")
    full_table_html = utils.metrics_df_to_table_html(df, additional_class="full-table")

    # Render the template with the table HTML
    return render_template('index.html', main_table_html=main_table_html, full_table_html=full_table_html)

@app.route('/model/<model_name>')
def model_detail(model_name):

    df = pd.read_csv(f'static/models_data/{model_name}/cfa_metrics.csv')

    df = df.round(3)
    df.insert(0, '#', '')

    up_arrow, down_arrow = "↑", "↓"

    metrics_to_show = [df.columns[0], df.columns[1], "CFI", "SRMR", "RMSEA"]
    df = df[metrics_to_show].copy()
    df = df.rename(columns={
        "CFI": f"CFI ({up_arrow})",
        "SRMR": f"SRMR ({down_arrow})",
        "RMSEA": f"RMSEA ({down_arrow})",
    })
    classes = 'table table-striped table-bordered'
    cfa_table_html = df.to_html(classes=classes, escape=False, index=False)

    # Load model specific description
    model_detail_file = f'static/models_data/{model_name}/model_detail.html'
    if os.path.exists(model_detail_file):
        # If the file exists, open and read the HTML file as a string
        with open(model_detail_file, 'r', encoding='utf-8') as file:
            model_detail = file.read()
    else:
        model_detail = "<p>No additional detail is provided for this model.</p>"

    return render_template(
        'model_detail.html',
        model_name=model_name,
        model_detail=model_detail,
        cfa_table_html=cfa_table_html
    )

@app.route('/about')
def about():
    return render_template('about.html')

@app.route('/new_model')
def new_model():
    return render_template('new_model.html')

@app.route('/model_submitted')
def model_submitted():
    return render_template('model_submitted.html')

@app.route('/failed_submission')
def failed_submission():
    return render_template('failed_submission.html')


@app.route('/submit_model', methods=['POST'])
def submit_model():
    model_name = request.form['model_name']
    pull_request_link = request.form['pull_request_link']
    email = request.form['email']
    description = request.form['description']

    # Handle ZIP file upload
    if 'model_files' not in request.files:
        return redirect(url_for('failed_submission'))

    file = request.files['model_files']

    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
        file.save(file_path)

        # Read the file content and encode it in base64
        with open(file_path, 'rb') as f:
            file_content = base64.b64encode(f.read()).decode('ascii')

        # Set up Postmark email client
        postmark = PostmarkClient(server_token=os.getenv('POSTMARK_SERVER_API'))

        # Send the email with the attachment
        postmark.emails.send(
            From='grgur.kovac@inria.fr',
            To='grgur.kovac@inria.fr',
            Subject=f'Stick to Your Role! Model Submission: {model_name}',
            HtmlBody=f"""
            <p><strong>Model Name:</strong> {model_name}</p>
            <p><strong>Pull Request Link:</strong> {pull_request_link}</p>
            <p><strong>Email:</strong> {email}</p>
            <p><strong>Description:</strong> {description}</p>
            """,
            Attachments=[{
                'Name': filename,
                'Content': file_content,
                'ContentType': 'application/zip'
            }]
        )
    else:
        return redirect(url_for('failed_submission'))

    return redirect(url_for('model_submitted'))


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860, debug=True)