Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -19,13 +19,23 @@ def get_prediction(question):
|
|
19 |
predicted_answer = tokenizer.convert_tokens_to_string(output_tokens)
|
20 |
return predicted_answer
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Gradio interface for user input and output
|
23 |
def gradio_interface(question, correct_answer):
|
24 |
-
|
25 |
return {
|
26 |
-
"
|
27 |
-
"
|
28 |
-
"
|
|
|
29 |
}
|
30 |
|
31 |
# Gradio app setup
|
@@ -36,10 +46,10 @@ interface = gr.Interface(
|
|
36 |
gr.Textbox(label="Correct Answer"),
|
37 |
],
|
38 |
outputs=[
|
39 |
-
gr.JSON(label="Results")
|
40 |
],
|
41 |
title="Math Question Solver",
|
42 |
-
description="Enter a math question to get the model prediction."
|
43 |
)
|
44 |
|
45 |
if __name__ == "__main__":
|
|
|
19 |
predicted_answer = tokenizer.convert_tokens_to_string(output_tokens)
|
20 |
return predicted_answer
|
21 |
|
22 |
+
# Function to perform majority voting across multiple predictions
|
23 |
+
def majority_vote(question, num_iterations=10):
|
24 |
+
all_predictions = []
|
25 |
+
for _ in range(num_iterations):
|
26 |
+
prediction = get_prediction(question)
|
27 |
+
all_predictions.append(prediction)
|
28 |
+
majority_voted_pred = max(set(all_predictions), key=all_predictions.count)
|
29 |
+
return majority_voted_pred, all_predictions
|
30 |
+
|
31 |
# Gradio interface for user input and output
|
32 |
def gradio_interface(question, correct_answer):
|
33 |
+
final_prediction, all_predictions = majority_vote(question, num_iterations=10)
|
34 |
return {
|
35 |
+
"Question": question,
|
36 |
+
"Generated Answers (10 iterations)": all_predictions,
|
37 |
+
"Majority-Voted Prediction": final_prediction,
|
38 |
+
"Correct Answer": correct_answer
|
39 |
}
|
40 |
|
41 |
# Gradio app setup
|
|
|
46 |
gr.Textbox(label="Correct Answer"),
|
47 |
],
|
48 |
outputs=[
|
49 |
+
gr.JSON(label="Results"), # Display the results in a JSON format
|
50 |
],
|
51 |
title="Math Question Solver",
|
52 |
+
description="Enter a math question to get the model prediction and see all generated answers.",
|
53 |
)
|
54 |
|
55 |
if __name__ == "__main__":
|