AddieFoote commited on
Commit
ad3368d
·
1 Parent(s): ce873bc

add app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
+
5
+ model_name = "AddieFoote0/arithmetic-300M-MaxEnt-distilled-relearned"
6
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ if hasattr(torch, "compile"):
9
+ model = torch.compile(model)
10
+ print("compiled model")
11
+ else:
12
+ print("no compile")
13
+
14
+
15
+ def generate_response(prompt):
16
+ inputs = tokenizer(prompt, return_tensors="pt")
17
+ outputs = model.generate(**inputs, max_new_tokens=5, temperature=1.0)
18
+ input_length = inputs['input_ids'].shape[1]
19
+ new_token_ids = outputs[0][input_length:]
20
+ new_tokens = tokenizer.decode(new_token_ids, skip_special_tokens=False)
21
+ return new_tokens
22
+
23
+ iface = gr.Interface(
24
+ fn=generate_response,
25
+ inputs=gr.Textbox(label="Enter your prompt"),
26
+ outputs=gr.Textbox(label="Model Response"),
27
+ title="Arithmetic Model Demo",
28
+ )
29
+
30
+ iface.launch()