stefstefstef commited on
Commit
7bc7885
1 Parent(s): 0c7be75

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ gr.load("models/bigcode/starcoder2-7b").launch()
5
+
6
+ checkpoint = "bigcode/starcoder2-7b"
7
+ device = "cuda" # for GPU usage or "cpu" for CPU usage
8
+
9
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
10
+ # for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
11
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
12
+
13
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
14
+ outputs = model.generate(inputs)
15
+ print(tokenizer.decode(outputs[0]))