Makima57 commited on
Commit
ffdb4c9
·
verified ·
1 Parent(s): 291e22e

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +16 -6
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
- predicted_answer = get_prediction(question)
25
  return {
26
- "question": question,
27
- "predicted_answer": predicted_answer,
28
- "correct_answer": correct_answer,
 
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__":