Spaces:
Runtime error
Runtime error
MBear
commited on
Commit
·
1d31443
1
Parent(s):
d1e9e74
add model
Browse files
app.py
CHANGED
@@ -1,7 +1,14 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(
|
4 |
-
|
|
|
|
|
|
|
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()
|