Rich Jones
commited on
Commit
·
e617f47
1
Parent(s):
51aea80
display scores on load
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import pandas as pd
|
|
| 8 |
def score_file(csv_file, model_name):
|
| 9 |
# Simulate a delay (replace with your actual processing)
|
| 10 |
time.sleep(5)
|
| 11 |
-
#
|
| 12 |
result = {
|
| 13 |
'individual_scores': {
|
| 14 |
'ab': 100.0, 'advanced_geometry': 100.0, 'aiw': 100.0,
|
|
@@ -61,37 +61,44 @@ conn.commit()
|
|
| 61 |
def process_file(file_obj, model_name):
|
| 62 |
# Run the scoring function
|
| 63 |
result = score_file(file_obj, model_name)
|
| 64 |
-
|
| 65 |
# Save the result to the database
|
| 66 |
result_json = json.dumps(result)
|
| 67 |
total_score = result.get("total_score", 0)
|
| 68 |
c.execute("INSERT INTO results (model_name, total_score, result_json) VALUES (?, ?, ?)",
|
| 69 |
(model_name, total_score, result_json))
|
| 70 |
conn.commit()
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
#
|
|
|
|
|
|
|
|
|
|
| 73 |
c.execute("SELECT id, model_name, total_score, timestamp FROM results ORDER BY total_score DESC")
|
| 74 |
records = c.fetchall()
|
| 75 |
# Create a pandas DataFrame for a nicer display
|
| 76 |
df = pd.DataFrame(records, columns=["ID", "Model Name", "Total Score", "Timestamp"])
|
| 77 |
-
|
| 78 |
-
# Return the individual run result and the table of saved results
|
| 79 |
-
return f"Current Run Result:\n{json.dumps(result, indent=2)}", df
|
| 80 |
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
-
gr.Markdown("#
|
| 83 |
-
gr.Markdown("Upload a CSV file
|
| 84 |
-
|
| 85 |
with gr.Row():
|
| 86 |
file_input = gr.File(label="Upload CSV File", file_types=['.csv'])
|
| 87 |
model_input = gr.Textbox(label="Model Name")
|
| 88 |
-
|
| 89 |
run_button = gr.Button("Run Scoring")
|
| 90 |
-
|
| 91 |
result_output = gr.Textbox(label="Score File Result", lines=15)
|
| 92 |
table_output = gr.Dataframe(label="All Saved Results (sorted by Total Score)")
|
| 93 |
-
|
| 94 |
run_button.click(fn=process_file, inputs=[file_input, model_input], outputs=[result_output, table_output])
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
demo.launch()
|
| 97 |
|
|
|
|
| 8 |
def score_file(csv_file, model_name):
|
| 9 |
# Simulate a delay (replace with your actual processing)
|
| 10 |
time.sleep(5)
|
| 11 |
+
# Dummy output; replace with your actual scoring logic.
|
| 12 |
result = {
|
| 13 |
'individual_scores': {
|
| 14 |
'ab': 100.0, 'advanced_geometry': 100.0, 'aiw': 100.0,
|
|
|
|
| 61 |
def process_file(file_obj, model_name):
|
| 62 |
# Run the scoring function
|
| 63 |
result = score_file(file_obj, model_name)
|
| 64 |
+
|
| 65 |
# Save the result to the database
|
| 66 |
result_json = json.dumps(result)
|
| 67 |
total_score = result.get("total_score", 0)
|
| 68 |
c.execute("INSERT INTO results (model_name, total_score, result_json) VALUES (?, ?, ?)",
|
| 69 |
(model_name, total_score, result_json))
|
| 70 |
conn.commit()
|
| 71 |
+
|
| 72 |
+
# Retrieve updated records, sorted by total_score descending
|
| 73 |
+
df = get_saved_results()
|
| 74 |
|
| 75 |
+
# Return the individual run result and the table of saved results
|
| 76 |
+
return f"Current Run Result:\n{json.dumps(result, indent=2)}", df
|
| 77 |
+
|
| 78 |
+
def get_saved_results():
|
| 79 |
c.execute("SELECT id, model_name, total_score, timestamp FROM results ORDER BY total_score DESC")
|
| 80 |
records = c.fetchall()
|
| 81 |
# Create a pandas DataFrame for a nicer display
|
| 82 |
df = pd.DataFrame(records, columns=["ID", "Model Name", "Total Score", "Timestamp"])
|
| 83 |
+
return df
|
|
|
|
|
|
|
| 84 |
|
| 85 |
with gr.Blocks() as demo:
|
| 86 |
+
gr.Markdown("# RGBench [WIP]")
|
| 87 |
+
gr.Markdown("Upload a CSV file with your completed results and enter the name of your model. RGBench will score and save your results.")
|
| 88 |
+
|
| 89 |
with gr.Row():
|
| 90 |
file_input = gr.File(label="Upload CSV File", file_types=['.csv'])
|
| 91 |
model_input = gr.Textbox(label="Model Name")
|
| 92 |
+
|
| 93 |
run_button = gr.Button("Run Scoring")
|
| 94 |
+
|
| 95 |
result_output = gr.Textbox(label="Score File Result", lines=15)
|
| 96 |
table_output = gr.Dataframe(label="All Saved Results (sorted by Total Score)")
|
| 97 |
+
|
| 98 |
run_button.click(fn=process_file, inputs=[file_input, model_input], outputs=[result_output, table_output])
|
| 99 |
+
|
| 100 |
+
# Load the table data on page load
|
| 101 |
+
demo.load(fn=get_saved_results, inputs=[], outputs=table_output)
|
| 102 |
|
| 103 |
demo.launch()
|
| 104 |
|