Rich Jones commited on
Commit
ad13e2f
·
1 Parent(s): e701deb
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import sqlite3
3
+ import time
4
+ import json
5
+ import pandas as pd
6
+
7
+ # Example score_file function (simulate long running task)
8
+ def score_file(csv_file, model_name):
9
+ # Simulate a delay (replace with your actual processing)
10
+ time.sleep(5)
11
+ # Here is a dummy example output; replace it with your actual scoring logic.
12
+ result = {
13
+ 'individual_scores': {
14
+ 'ab': 100.0, 'advanced_geometry': 100.0, 'aiw': 100.0,
15
+ 'base_conversion': 100.0, 'basic_arithmetic': 100.0, 'bf': 100.0,
16
+ 'binary_alternation': 100.0, 'binary_matrix': 100.0, 'bitwise_arithmetic': 100.0,
17
+ 'boxnet': 1.0, 'caesar_cipher': 100.0, 'calendar_arithmetic': 100.0,
18
+ 'chain_sum': 100.0, 'circuit_logic': 100.0, 'color_cube_rotation': 100.0,
19
+ 'complex_arithmetic': 100.0, 'count_bits': 100.0, 'count_primes': 100.0,
20
+ 'course_schedule': 100.0, 'cryptarithm': 100.0, 'decimal_arithmetic': 100.0,
21
+ 'decimal_chain_sum': 100.0, 'dice': 100.0, 'emoji_mystery': 100.0,
22
+ 'family_relationships': 100.0, 'figlet_font': 100.0, 'fraction_simplification': 100.0,
23
+ 'game_of_life': 100.0, 'game_of_life_halting': 100.0, 'graph_color': 0.0,
24
+ 'group_anagrams': 100.0, 'intermediate_integration': 100.0, 'isomorphic_strings': 100.0,
25
+ 'jugs': 100.0, 'largest_island': 100.0, 'lcm': 100.0, 'leg_counting': 100.0,
26
+ 'letter_counting': 100.0, 'letter_jumble': 100.0, 'mahjong_puzzle': 100.0,
27
+ 'manipulate_matrix': 100.0, 'maze': 100.0, 'mini_sudoku': 100.0, 'modulo_grid': 100.0,
28
+ 'n_queens': 100.0, 'needle_haystack': 100.0, 'number_filtering': 100.0,
29
+ 'number_format': 100.0, 'number_sequence': 100.0, 'number_sorting': 100.0,
30
+ 'palindrome_generation': 100.0, 'palindrome_partitioning': 100.0,
31
+ 'polynomial_equations': 100.0, 'polynomial_multiplication': 0.0, 'pool_matrix': 100.0,
32
+ 'power_function': 100.0, 'prime_factorization': 100.0, 'products': 100.0,
33
+ 'propositional_logic': 0.0, 'quantum_lock': 100.0, 'ransom_note': 100.0,
34
+ 'rectangle_count': 100.0, 'rotate_matrix': 100.0, 'rotten_oranges': 100.0,
35
+ 'rush_hour': 0.0, 'self_reference': 100.0, 'sentence_reordering': 100.0,
36
+ 'shortest_path': 100.0, 'simple_equations': 100.0, 'simple_geometry': 100.0,
37
+ 'simple_integration': 100.0, 'sokoban': 100.0, 'spell_backward': 100.0,
38
+ 'spiral_matrix': 100.0, 'string_insertion': 100.0, 'string_manipulation': 100.0,
39
+ 'string_splitting': 100.0, 'string_synthesis': 100.0, 'sudoku': 100.0,
40
+ 'time_intervals': 100.0, 'tsumego': 100.0, 'word_sequence_reversal': 100.0,
41
+ 'zebra_puzzles': 100.0
42
+ },
43
+ 'total_score': 93.98795180722891
44
+ }
45
+ return result
46
+
47
+ # Initialize or connect to a SQLite database
48
+ conn = sqlite3.connect("results.db", check_same_thread=False)
49
+ c = conn.cursor()
50
+ c.execute("""
51
+ CREATE TABLE IF NOT EXISTS results (
52
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
53
+ model_name TEXT,
54
+ total_score REAL,
55
+ result_json TEXT,
56
+ timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
57
+ )
58
+ """)
59
+ conn.commit()
60
+
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 all records, sorted by total_score descending
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("# CSV Scoring App")
83
+ gr.Markdown("Upload a CSV file and enter a model name. The app will process the file with your `score_file` function, store the results, and display all results sorted by total score.")
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
+