hhxxtest1 commited on
Commit
33b29e2
·
verified ·
1 Parent(s): 12c72f4

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +31 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoTokenizer
2
+ import gradio as gr
3
+
4
+ tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
5
+ model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
6
+ model = model.eval()
7
+
8
+ def predict(input, history=None):
9
+ if history is None:
10
+ history = []
11
+ response, history = model.chat(tokenizer, input, history)
12
+ return history, history
13
+
14
+
15
+ with gr.Blocks() as demo:
16
+ gr.Markdown('''## ChatGLM-6B - unofficial demo
17
+ Unnoficial demo of the [ChatGLM-6B](https://github.com/THUDM/ChatGLM-6B/blob/main/README_en.md) model, trained on 1T tokens of English and Chinese
18
+ ''')
19
+ state = gr.State([])
20
+ chatbot = gr.Chatbot([], elem_id="chatbot").style(height=400)
21
+ with gr.Row():
22
+ with gr.Column(scale=4):
23
+ txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(container=False)
24
+ with gr.Column(scale=1):
25
+ button = gr.Button("Generate")
26
+ txt.submit(predict, [txt, state], [chatbot, state])
27
+ button.click(predict, [txt, state], [chatbot, state])
28
+ demo.queue().launch()
requirements.txt ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # basic requirements
2
+
3
+ transformers==4.40.0
4
+ cpm_kernels>=1.0.11
5
+ torch>=2.3.0
6
+ vllm>=0.4.2
7
+ gradio>=4.26.0
8
+ sentencepiece>=0.2.0
9
+ sentence_transformers>=2.7.0
10
+ accelerate>=0.29.2
11
+ streamlit>=1.33.0
12
+ fastapi>=0.110.0
13
+ loguru~=0.7.2
14
+ mdtex2html>=1.3.0
15
+ latex2mathml>=3.77.0
16
+ jupyter_client>=8.6.1
17
+
18
+ # for openai demo
19
+ openai>=1.30.1
20
+ pydantic>=2.7.1
21
+ sse-starlette>=2.1.0
22
+ uvicorn>=0.29.0
23
+ timm>=0.9.16
24
+ tiktoken>=0.6.0
25
+
26
+ # for langchain demo
27
+
28
+ langchain>=0.2.1
29
+ langchain_community>=0.2.0
30
+ langchainhub>=0.1.15
31
+ arxiv>=2.1.0