Add chatglm-6b model
Browse files
app.py
CHANGED
|
@@ -1,7 +1,18 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModel
|
| 3 |
|
| 4 |
+
def chat(text):
|
| 5 |
+
global model, tokenizer
|
| 6 |
+
response, history = model.chat(tokenizer, text, "", 64, 0.7, 0.95)
|
| 7 |
+
return response
|
| 8 |
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if __name__ == '__main__':
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
|
| 15 |
+
model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
|
| 16 |
+
model.eval()
|
| 17 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text")
|
| 18 |
+
iface.launch()
|