Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,15 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
-
from codeexecutor import postprocess_completion,get_majority_vote
|
| 7 |
|
| 8 |
# Define the model and tokenizer loading
|
| 9 |
model_prompt = "Solve the following mathematical problem: "
|
| 10 |
tokenizer = AutoTokenizer.from_pretrained("AI-MO/NuminaMath-7B-TIR")
|
| 11 |
model_path = snapshot_download(repo_id="Makima57/deepseek-math-Numina")
|
| 12 |
generator = ctranslate2.Generator(model_path, device="cpu", compute_type="int8")
|
| 13 |
-
iterations=10
|
| 14 |
|
| 15 |
# Function to generate predictions using the model
|
| 16 |
def get_prediction(question):
|
|
@@ -19,7 +18,7 @@ def get_prediction(question):
|
|
| 19 |
results = generator.generate_batch([input_tokens])
|
| 20 |
output_tokens = results[0].sequences[0]
|
| 21 |
predicted_answer = tokenizer.convert_tokens_to_string(output_tokens)
|
| 22 |
-
return predicted_answer
|
| 23 |
|
| 24 |
# Function to perform majority voting across multiple predictions
|
| 25 |
def majority_vote(question, num_iterations=10):
|
|
@@ -32,7 +31,7 @@ def majority_vote(question, num_iterations=10):
|
|
| 32 |
all_answer.append(answer)
|
| 33 |
majority_voted_pred = max(set(all_predictions), key=all_predictions.count)
|
| 34 |
majority_voted_ans=get_majority_vote(all_answer)
|
| 35 |
-
return majority_voted_pred, all_predictions,majority_voted_ans
|
| 36 |
|
| 37 |
# Gradio interface for user input and output
|
| 38 |
def gradio_interface(question, correct_answer):
|
|
@@ -57,8 +56,6 @@ demo = gr.Interface(
|
|
| 57 |
],
|
| 58 |
title="Math Question Solver",
|
| 59 |
description="Enter a math question to get the model prediction and see all generated answers.",
|
| 60 |
-
theme="huggingface",
|
| 61 |
-
layout="vertical",
|
| 62 |
live=True,
|
| 63 |
allow_flagging="never",
|
| 64 |
show_input=True,
|
|
@@ -66,6 +63,4 @@ demo = gr.Interface(
|
|
| 66 |
)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
| 1 |
+
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: "
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained("AI-MO/NuminaMath-7B-TIR")
|
| 10 |
model_path = snapshot_download(repo_id="Makima57/deepseek-math-Numina")
|
| 11 |
generator = ctranslate2.Generator(model_path, device="cpu", compute_type="int8")
|
| 12 |
+
iterations=10
|
| 13 |
|
| 14 |
# Function to generate predictions using the model
|
| 15 |
def get_prediction(question):
|
|
|
|
| 18 |
results = generator.generate_batch([input_tokens])
|
| 19 |
output_tokens = results[0].sequences[0]
|
| 20 |
predicted_answer = tokenizer.convert_tokens_to_string(output_tokens)
|
| 21 |
+
return predicted_answer
|
| 22 |
|
| 23 |
# Function to perform majority voting across multiple predictions
|
| 24 |
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, all_predictions,majority_voted_ans
|
| 35 |
|
| 36 |
# Gradio interface for user input and output
|
| 37 |
def gradio_interface(question, correct_answer):
|
|
|
|
| 56 |
],
|
| 57 |
title="Math Question Solver",
|
| 58 |
description="Enter a math question to get the model prediction and see all generated answers.",
|
|
|
|
|
|
|
| 59 |
live=True,
|
| 60 |
allow_flagging="never",
|
| 61 |
show_input=True,
|
|
|
|
| 63 |
)
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
+
demo.launch()
|
|
|
|
|
|