MBear commited on
Commit
1d31443
·
1 Parent(s): d1e9e74
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,7 +1,14 @@
1
  import gradio as gr
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModel
3
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/codegeex2-6b", trust_remote_code=True)
4
+ model = AutoModel.from_pretrained("THUDM/codegeex2-6b", trust_remote_code=True, device='cuda')
5
+ model = model.eval()
6
 
7
+ def greet(prompt):
8
+ inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
9
+ outputs = model.generate(inputs, max_length=256, top_k=1)
10
+ response = tokenizer.decode(outputs[0])
11
+ return response
12
 
13
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
14
  iface.launch()