Pra-tham commited on
Commit
23c6543
1 Parent(s): 5a97268
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -1,25 +1,40 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  from model import *
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def evaluate_response(problem):
10
  # problem=b'what is angle x if angle y is 60 degree and angle z in 60 degree of a traingle'
11
- problem=problem.decode('utf-8')
12
- results, answers = [[],[]]
13
- messages = [{"role": "user", "content": problem }]
14
- query_prompt = tokenizer.apply_chat_template(messages, tokenize=False)
15
- raw_output = pipeline(query_prompt, max_new_tokens=2048, do_sample=True, temperature=0.9, return_full_text=False)
 
16
 
17
- raw_output = raw_output[0]['generated_text']
18
  # result_output, code_output = process_output(raw_output)
19
- return raw_output
20
 
21
  def respond(
22
- message,
23
  history: list[tuple[str, str]],
24
  system_message,
25
  max_tokens,
 
1
  import gradio as gr
2
+ # from huggingface_hub import InferenceClient
3
  from model import *
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
7
+ # client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
+ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig, set_seed
9
+ # from accelerate import infer_auto_device_map as iadm
10
+
11
+ import torch
12
+ from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
13
+
14
+ model_name = "deepseek-ai/deepseek-math-7b-instruct"
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
17
+ model.generation_config = GenerationConfig.from_pretrained(model_name)
18
+ model.generation_config.pad_token_id = model.generation_config.eos_token_id
19
+
20
+
21
+
22
 
23
  def evaluate_response(problem):
24
  # problem=b'what is angle x if angle y is 60 degree and angle z in 60 degree of a traingle'
25
+ problem=problem+'\nPlease reason step by step, and put your final answer within \\boxed{}.'
26
+ messages = [
27
+ {"role": "user", "content": problem}
28
+ ]
29
+ input_tensor = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
30
+ outputs = model.generate(input_tensor.to(model.device), max_new_tokens=100)
31
 
32
+ result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
33
  # result_output, code_output = process_output(raw_output)
34
+ return result
35
 
36
  def respond(
37
+ evaluate_response,
38
  history: list[tuple[str, str]],
39
  system_message,
40
  max_tokens,