Spaces:
Running
on
Zero
Running
on
Zero
Delete app.py
Browse files
app.py
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
import spaces
|
2 |
-
import gradio as gr
|
3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
4 |
-
import torch
|
5 |
-
|
6 |
-
title = """# 🙋🏻♂️Welcome to🌟Tonic's🔮🪄DeepSeek📉Math
|
7 |
-
You can build with this endpoint using 🔮🪄DeepSeek📉Math. The demo is still a work in progress and we're looking forward to build downstream tasks that showcase outstanding mathematical reasoning. Have any ideas ? join us below !
|
8 |
-
You can also use 🔮🪄DeepSeek📉Math by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/Math?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
|
9 |
-
Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community 👻 [](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) Math with [introspector](https://huggingface.co/introspector) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to 🌟 [SciTonic](https://github.com/Tonic-AI/scitonic) 🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
|
10 |
-
"""
|
11 |
-
|
12 |
-
model_name = "deepseek-ai/deepseek-math-7b-instruct"
|
13 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
14 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
|
15 |
-
model.generation_config = GenerationConfig.from_pretrained(model_name)
|
16 |
-
model.generation_config.pad_token_id = model.generation_config.eos_token_id
|
17 |
-
|
18 |
-
@spaces.GPU
|
19 |
-
def solve_math_problem(question, max_tokens):
|
20 |
-
prompt = f"User: {question}\nPlease reason step by step, and put your final answer within \\boxed{{}}.\nAssistant:"
|
21 |
-
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
|
22 |
-
outputs = model.generate(input_ids, max_length=max_tokens + input_ids.shape[1], pad_token_id=model.generation_config.pad_token_id)
|
23 |
-
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
-
return result
|
25 |
-
|
26 |
-
def main():
|
27 |
-
with gr.Blocks() as demo:
|
28 |
-
gr.Markdown(title)
|
29 |
-
with gr.Row():
|
30 |
-
question = gr.Textbox(lines=5, label="Enter your math problem")
|
31 |
-
max_tokens = gr.Slider(minimum=150, maximum=1200, default=250, label="Max Tokens")
|
32 |
-
submit_button = gr.Button("Solve")
|
33 |
-
output = gr.Textbox(label="🔮🪄DeepSeek📉Math")
|
34 |
-
|
35 |
-
submit_button.click(fn=solve_math_problem, inputs=[question, max_tokens], outputs=output)
|
36 |
-
|
37 |
-
demo.launch()
|
38 |
-
|
39 |
-
if __name__ == "__main__":
|
40 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|