Spaces:
Runtime error
Runtime error
File size: 3,301 Bytes
2a01fa1 01d13d1 80a95ed 2a01fa1 01d13d1 2a01fa1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import spaces
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
import torch
title = """# ๐๐ปโโ๏ธWelcome to๐Tonic's๐ฎDeepSeekMath๐
You can build with this endpoint using๐ฎDeepSeekMath๐. 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 !
You can also use ๐ฎDeepSeekMath๐ 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>
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 ๐ค
"""
model_name = "deepseek-ai/deepseek-math-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
model.generation_config = GenerationConfig.from_pretrained(model_name)
model.generation_config.pad_token_id = model.generation_config.eos_token_id
@spaces.GPU
def solve_math_problem(question, max_tokens):
prompt = f"User: {question}\nPlease reason step by step, and put your final answer within \\boxed{{}}.\nAssistant:"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
outputs = model.generate(input_ids, max_length=max_tokens + input_ids.shape[1], pad_token_id=model.generation_config.pad_token_id)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
return result
def main():
with gr.Blocks() as demo:
gr.Markdown(title)
with gr.Row():
question = gr.Code(language='python', value='what is the integral of x^2 from 0 to 2?', label="Enter your math problem")
max_tokens = gr.Slider(minimum=150, maximum=1200, value=250, label="Max Tokens")
submit_button = gr.Button("Solve")
output = gr.Code(label="๐ฎDeepSeekMath๐", interactive=False)
submit_button.click(fn=solve_math_problem, inputs=[question, max_tokens], outputs=output)
demo.launch()
if __name__ == "__main__":
main() |