Spaces:
Running
Running
Update app.py
Browse filesonly show major voted solution with steps
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import ctranslate2
|
3 |
from transformers import AutoTokenizer
|
4 |
from huggingface_hub import snapshot_download
|
5 |
-
from codeexecutor import postprocess_completion, get_majority_vote
|
6 |
|
7 |
# Define the model and tokenizer loading
|
8 |
model_prompt = "Solve the following mathematical problem: "
|
@@ -31,20 +31,27 @@ def majority_vote(question, num_iterations=10):
|
|
31 |
all_answer.append(answer)
|
32 |
majority_voted_pred = max(set(all_predictions), key=all_predictions.count)
|
33 |
majority_voted_ans = get_majority_vote(all_answer)
|
34 |
-
return majority_voted_pred,
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Gradio interface for user input and output
|
37 |
def gradio_interface(question, correct_answer):
|
38 |
-
final_prediction,
|
|
|
39 |
return {
|
40 |
"Question": question,
|
41 |
-
"Generated Answers (10 iterations)": all_predictions,
|
42 |
"Majority-Voted Prediction": final_prediction,
|
43 |
-
"Correct
|
44 |
-
"Majority
|
|
|
45 |
}
|
46 |
|
47 |
-
# Custom CSS for enhanced design
|
48 |
custom_css = """
|
49 |
body {
|
50 |
background-color: #fafafa;
|
@@ -86,9 +93,7 @@ custom_css = """
|
|
86 |
#math_question, #correct_answer {
|
87 |
font-size: 20px;
|
88 |
font-family: 'Poppins', sans-serif;
|
89 |
-
font-weight: 500px;
|
90 |
-
|
91 |
-
|
92 |
color: #007acc;
|
93 |
margin-bottom: 5px;
|
94 |
display: inline-block;
|
@@ -133,7 +138,6 @@ custom_css = """
|
|
133 |
font-weight: bold;
|
134 |
color: #00796b;
|
135 |
}
|
136 |
-
|
137 |
"""
|
138 |
|
139 |
# Gradio app setup
|
@@ -147,9 +151,9 @@ interface = gr.Interface(
|
|
147 |
gr.JSON(label="π Results"), # Display the results in a JSON format
|
148 |
],
|
149 |
title="π’ Math Question Solver",
|
150 |
-
description="Enter a math question to get the
|
151 |
css=custom_css # Apply custom CSS
|
152 |
)
|
153 |
|
154 |
if __name__ == "__main__":
|
155 |
-
interface.launch()
|
|
|
2 |
import ctranslate2
|
3 |
from transformers import AutoTokenizer
|
4 |
from huggingface_hub import snapshot_download
|
5 |
+
from codeexecutor import postprocess_completion, get_majority_vote, get_solution_steps
|
6 |
|
7 |
# Define the model and tokenizer loading
|
8 |
model_prompt = "Solve the following mathematical problem: "
|
|
|
31 |
all_answer.append(answer)
|
32 |
majority_voted_pred = max(set(all_predictions), key=all_predictions.count)
|
33 |
majority_voted_ans = get_majority_vote(all_answer)
|
34 |
+
return majority_voted_pred, majority_voted_ans
|
35 |
+
|
36 |
+
# Function to get steps for solving the problem
|
37 |
+
def get_solution_steps(question):
|
38 |
+
# Assuming 'get_solution_steps' is a function that provides steps for solving the problem
|
39 |
+
steps = get_solution_steps(question) # You need to implement this function based on how steps are generated
|
40 |
+
return steps
|
41 |
|
42 |
# Gradio interface for user input and output
|
43 |
def gradio_interface(question, correct_answer):
|
44 |
+
final_prediction, final_answer = majority_vote(question, iterations)
|
45 |
+
solution_steps = get_solution_steps(question) # Fetch the steps to solve the problem
|
46 |
return {
|
47 |
"Question": question,
|
|
|
48 |
"Majority-Voted Prediction": final_prediction,
|
49 |
+
"Correct Solution": correct_answer,
|
50 |
+
"Majority Answer": final_answer,
|
51 |
+
"Solution Steps": solution_steps
|
52 |
}
|
53 |
|
54 |
+
# Custom CSS for enhanced design (unchanged)
|
55 |
custom_css = """
|
56 |
body {
|
57 |
background-color: #fafafa;
|
|
|
93 |
#math_question, #correct_answer {
|
94 |
font-size: 20px;
|
95 |
font-family: 'Poppins', sans-serif;
|
96 |
+
font-weight: 500px;
|
|
|
|
|
97 |
color: #007acc;
|
98 |
margin-bottom: 5px;
|
99 |
display: inline-block;
|
|
|
138 |
font-weight: bold;
|
139 |
color: #00796b;
|
140 |
}
|
|
|
141 |
"""
|
142 |
|
143 |
# Gradio app setup
|
|
|
151 |
gr.JSON(label="π Results"), # Display the results in a JSON format
|
152 |
],
|
153 |
title="π’ Math Question Solver",
|
154 |
+
description="Enter a math question to get the majority-voted prediction and the steps to solve it.",
|
155 |
css=custom_css # Apply custom CSS
|
156 |
)
|
157 |
|
158 |
if __name__ == "__main__":
|
159 |
+
interface.launch()
|