From 0e43be664f6011438f09f05e40044de30d714d17 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 12:46:50 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E6=9B=B4=E5=8A=A0=E6=98=8E=E7=A1=AE?= =?UTF-8?q?=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index f594164..c051398 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,8 @@ +python_version == 3.10.* SwissArmyTransformer>=0.3.6 -torch>1.10.0 -torchvision +torch==1.13.0 +torchvision==0.14.0 +torchaudio==0.13.0 transformers>=4.27.1 mdtex2html gradio \ No newline at end of file From 1be04ea3052a8fc07a39863a7d6e484075c7c886 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 12:55:48 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0git=E5=BF=BD=E8=A7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3bdb9ed..8865eaa 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,4 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +.idea/ \ No newline at end of file From fe3c35a3e57fcce9fc1a6902a5089c8497bae1fc Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:04:34 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E5=8F=AF=E9=80=9A=E8=BF=87=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E8=A1=8C=E5=8F=82=E6=95=B0=E5=AE=9A=E4=B9=89server=5F?= =?UTF-8?q?name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_demo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_demo.py b/web_demo.py index d0f705a..2086deb 100644 --- a/web_demo.py +++ b/web_demo.py @@ -116,7 +116,7 @@ def main(args): print(gr.__version__) demo.queue(concurrency_count=10) - demo.launch(share=args.share) + demo.launch(share=args.share,server_name=args.server_name) if __name__ == '__main__': @@ -124,6 +124,7 @@ def main(args): parser = argparse.ArgumentParser() parser.add_argument("--quant", choices=[8, 4], type=int, default=None) parser.add_argument("--share", action="store_true") + parser.add_argument("--server_name", type=str, default="127.0.0.1") args = parser.parse_args() main(args) \ No newline at end of file From fbb6c5469bedfb9705703956748db1a8f7bd95ff Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:04:47 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_demo.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/web_demo.py b/web_demo.py index 2086deb..4d518f3 100644 --- a/web_demo.py +++ b/web_demo.py @@ -7,6 +7,7 @@ from model import is_chinese, get_infer_setting, generate_input, chat import torch + def generate_text_with_image(input_text, image, history=[], request_data=dict(), is_zh=True): input_para = { "max_length": 2048, @@ -19,17 +20,17 @@ def generate_text_with_image(input_text, image, history=[], request_data=dict(), input_para.update(request_data) input_data = generate_input(input_text, image, history, input_para, image_is_encoded=False) - input_image, gen_kwargs = input_data['input_image'], input_data['gen_kwargs'] + input_image, gen_kwargs = input_data['input_image'], input_data['gen_kwargs'] with torch.no_grad(): answer, history, _ = chat(None, model, tokenizer, input_text, history=history, image=input_image, \ - max_length=gen_kwargs['max_length'], top_p=gen_kwargs['top_p'], \ - top_k = gen_kwargs['top_k'], temperature=gen_kwargs['temperature'], english=not is_zh) + max_length=gen_kwargs['max_length'], top_p=gen_kwargs['top_p'], \ + top_k=gen_kwargs['top_k'], temperature=gen_kwargs['temperature'], english=not is_zh) return answer def request_model(input_text, temperature, top_p, image_prompt, result_previous): result_text = [(ele[0], ele[1]) for ele in result_previous] - for i in range(len(result_text)-1, -1, -1): + for i in range(len(result_text) - 1, -1, -1): if result_text[i][0] == "" or result_text[i][1] == "": del result_text[i] print(f"history {result_text}") @@ -43,7 +44,7 @@ def request_model(input_text, temperature, top_p, image_prompt, result_previous) return input_text, result_text elif input_text == "": result_text.append((input_text, 'Text empty! Please enter text and retry.')) - return "", result_text + return "", result_text request_para = {"temperature": temperature, "top_p": top_p} image = Image.open(image_prompt) @@ -73,6 +74,7 @@ def request_model(input_text, temperature, top_p, image_prompt, result_previous) def clear_fn(value): return "", [("", "Hi, What do you want to know about this image?")], None + def clear_fn2(value): return [("", "Hi, What do you want to know about this image?")] @@ -81,13 +83,14 @@ def main(args): gr.close_all() global model, tokenizer model, tokenizer = get_infer_setting(gpu_device=0, quant=args.quant) - + with gr.Blocks(css='style.css') as demo: gr.Markdown(DESCRIPTION) with gr.Row(): with gr.Column(scale=4.5): with gr.Group(): - input_text = gr.Textbox(label='Input Text', placeholder='Please enter text prompt below and press ENTER.') + input_text = gr.Textbox(label='Input Text', + placeholder='Please enter text prompt below and press ENTER.') with gr.Row(): run_button = gr.Button('Generate') clear_button = gr.Button('Clear') @@ -100,15 +103,16 @@ def main(args): with gr.Row(): maintenance_notice = gr.Markdown(MAINTENANCE_NOTICE1) with gr.Column(scale=5.5): - result_text = gr.components.Chatbot(label='Multi-round conversation History', value=[("", "Hi, What do you want to know about this image?")]).style(height=550) + result_text = gr.components.Chatbot(label='Multi-round conversation History', value=[ + ("", "Hi, What do you want to know about this image?")]).style(height=550) gr.Markdown(NOTES) print(gr.__version__) - run_button.click(fn=request_model,inputs=[input_text, temperature, top_p, image_prompt, result_text], - outputs=[input_text, result_text]) - input_text.submit(fn=request_model,inputs=[input_text, temperature, top_p, image_prompt, result_text], + run_button.click(fn=request_model, inputs=[input_text, temperature, top_p, image_prompt, result_text], outputs=[input_text, result_text]) + input_text.submit(fn=request_model, inputs=[input_text, temperature, top_p, image_prompt, result_text], + outputs=[input_text, result_text]) clear_button.click(fn=clear_fn, inputs=clear_button, outputs=[input_text, result_text, image_prompt]) image_prompt.upload(fn=clear_fn2, inputs=clear_button, outputs=[result_text]) image_prompt.clear(fn=clear_fn2, inputs=clear_button, outputs=[result_text]) @@ -116,15 +120,16 @@ def main(args): print(gr.__version__) demo.queue(concurrency_count=10) - demo.launch(share=args.share,server_name=args.server_name) + demo.launch(share=args.share, server_name=args.server_name) if __name__ == '__main__': import argparse + parser = argparse.ArgumentParser() parser.add_argument("--quant", choices=[8, 4], type=int, default=None) parser.add_argument("--share", action="store_true") parser.add_argument("--server_name", type=str, default="127.0.0.1") args = parser.parse_args() - main(args) \ No newline at end of file + main(args) From 7153d36b29313658492af57afc3246d8ecb3fe70 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:07:31 +0800 Subject: [PATCH 05/16] =?UTF-8?q?API=E6=9C=8D=E5=8A=A1=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89quant=E5=80=BC=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=9C=A8=E4=BD=8E=E6=98=BE=E5=AD=98=E6=9C=BA=E5=99=A8=E4=B8=8A?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 3d15db1..7db1043 100644 --- a/api.py +++ b/api.py @@ -6,8 +6,15 @@ import datetime import torch + +# 命令行参数 +import argparse +parser = argparse.ArgumentParser() +parser.add_argument("--quant", choices=[8, 4], type=int, default=None) +args = parser.parse_args() + gpu_number = 0 -model, tokenizer = get_infer_setting(gpu_device=gpu_number) +model, tokenizer = get_infer_setting(gpu_device=gpu_number,quant=args.quant) app = FastAPI() @app.post('/') From b0ec136c364a51d8626cbf22b30c49b5a74fd26b Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:07:43 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/api.py b/api.py index 7db1043..7a0caef 100644 --- a/api.py +++ b/api.py @@ -6,17 +6,19 @@ import datetime import torch - # 命令行参数 import argparse + parser = argparse.ArgumentParser() parser.add_argument("--quant", choices=[8, 4], type=int, default=None) args = parser.parse_args() gpu_number = 0 -model, tokenizer = get_infer_setting(gpu_device=gpu_number,quant=args.quant) +model, tokenizer = get_infer_setting(gpu_device=gpu_number, quant=args.quant) app = FastAPI() + + @app.post('/') async def visual_glm(request: Request): json_post_raw = await request.json() @@ -37,12 +39,12 @@ async def visual_glm(request: Request): is_zh = is_chinese(input_text) input_data = generate_input(input_text, input_image_encoded, history, input_para) - input_image, gen_kwargs = input_data['input_image'], input_data['gen_kwargs'] + input_image, gen_kwargs = input_data['input_image'], input_data['gen_kwargs'] with torch.no_grad(): answer, history, _ = chat(None, model, tokenizer, input_text, history=history, image=input_image, \ - max_length=gen_kwargs['max_length'], top_p=gen_kwargs['top_p'], \ - top_k = gen_kwargs['top_k'], temperature=gen_kwargs['temperature'], english=not is_zh) - + max_length=gen_kwargs['max_length'], top_p=gen_kwargs['top_p'], \ + top_k=gen_kwargs['top_k'], temperature=gen_kwargs['temperature'], english=not is_zh) + now = datetime.datetime.now() time = now.strftime("%Y-%m-%d %H:%M:%S") response = { @@ -55,4 +57,4 @@ async def visual_glm(request: Request): if __name__ == '__main__': - uvicorn.run(app, host='0.0.0.0', port=8080, workers=1) \ No newline at end of file + uvicorn.run(app, host='0.0.0.0', port=8080, workers=1) From a5cfe03f4a47832da8e5ae01b5237a92587205de Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:10:08 +0800 Subject: [PATCH 07/16] =?UTF-8?q?Python=E4=BE=9D=E8=B5=96=E4=B8=8D?= =?UTF-8?q?=E5=86=99=E5=9C=A8requirements.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index c051398..45205c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -python_version == 3.10.* SwissArmyTransformer>=0.3.6 torch==1.13.0 torchvision==0.14.0 From 4dd9e33f44456ab327ae15297f54eb40775a3a83 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:15:03 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E6=9B=B4=E5=85=B7=E4=BD=93=E7=9A=84?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++++++++ README_en.md | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/README.md b/README.md index f706f60..511f673 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,17 @@ VisualGLM-6B 可以进行图像的描述的相关知识的问答。 ## 使用 +通过测试: + +CentOS Linux release 7.9.2009 (Core) + +NVIDIA Driver Version: 525.105.17 + +cuda_11.7 + +cuDNN v8.9.3 (July 11th, 2023), for CUDA 11.x + +Python 3.10.12 ### 模型推理 diff --git a/README_en.md b/README_en.md index 8b47449..8b3745a 100644 --- a/README_en.md +++ b/README_en.md @@ -38,6 +38,19 @@ VisualGLM-6B can answer questions related to image description. ## Usage + +test passed: + +CentOS Linux release 7.9.2009 (Core) + +NVIDIA Driver Version: 525.105.17 + +cuda_11.7 + +cuDNN v8.9.3 (July 11th, 2023), for CUDA 11.x + +Python 3.10.12 + ### Model Inference Install dependencies with pip From 1670cdd8dc5d57f6429e13be193c8c0909a635c0 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:21:38 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=BD=A2=E5=8F=82=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_demo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_demo.py b/web_demo.py index 4d518f3..5bcc234 100644 --- a/web_demo.py +++ b/web_demo.py @@ -120,7 +120,7 @@ def main(args): print(gr.__version__) demo.queue(concurrency_count=10) - demo.launch(share=args.share, server_name=args.server_name) + demo.launch(share=args.share, server_name=args.server_name, server_port=args.server_port) if __name__ == '__main__': @@ -130,6 +130,7 @@ def main(args): parser.add_argument("--quant", choices=[8, 4], type=int, default=None) parser.add_argument("--share", action="store_true") parser.add_argument("--server_name", type=str, default="127.0.0.1") + parser.add_argument("--server_port", type=int, default=7860) args = parser.parse_args() main(args) From ce2222d28faf2a9fa409dba2887e6f89425a75ff Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:21:57 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8865eaa..1e566cc 100644 --- a/.gitignore +++ b/.gitignore @@ -161,4 +161,5 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -.idea/ \ No newline at end of file +.idea/ +.run \ No newline at end of file From 4869007450c7e988e296e0dd93e31e525018499b Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 13:29:52 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E5=85=AC=E7=BD=91ip=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_demo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web_demo.py b/web_demo.py index 5bcc234..c51fe5e 100644 --- a/web_demo.py +++ b/web_demo.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import gradio as gr +import requests from PIL import Image import os import json @@ -120,6 +121,7 @@ def main(args): print(gr.__version__) demo.queue(concurrency_count=10) + print(f"Public IP address:{requests.get('https://api.ipify.org').text}") demo.launch(share=args.share, server_name=args.server_name, server_port=args.server_port) From 758dc559fe3e907cff61c405b39029451eec3ce8 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 14:01:30 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E5=85=81=E8=AE=B8=E4=B8=8D=E4=BC=A0?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/infer_util.py | 5 +++-- web_demo.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/model/infer_util.py b/model/infer_util.py index 342bd4f..84044ee 100644 --- a/model/infer_util.py +++ b/model/infer_util.py @@ -33,9 +33,10 @@ def is_chinese(text): return zh_pattern.search(text) def generate_input(input_text, input_image_prompt, history=[], input_para=None, image_is_encoded=True): + image = None if not image_is_encoded: image = input_image_prompt - else: + elif input_image_prompt: decoded_image = base64.b64decode(input_image_prompt) image = Image.open(BytesIO(decoded_image)) @@ -50,4 +51,4 @@ def process_image(image_encoded): image_path = f'./examples/{image_hash}.png' if not os.path.isfile(image_path): image.save(image_path) - return os.path.abspath(image_path) \ No newline at end of file + return os.path.abspath(image_path) \ No newline at end of file diff --git a/web_demo.py b/web_demo.py index c51fe5e..79b0704 100644 --- a/web_demo.py +++ b/web_demo.py @@ -38,17 +38,21 @@ def request_model(input_text, temperature, top_p, image_prompt, result_previous) is_zh = is_chinese(input_text) if image_prompt is None: - if is_zh: - result_text.append((input_text, '图片为空!请上传图片并重试。')) - else: - result_text.append((input_text, 'Image empty! Please upload a image and retry.')) - return input_text, result_text + ... + # if is_zh: + # result_text.append((input_text, '图片为空!请上传图片并重试。')) + # else: + # result_text.append((input_text, 'Image empty! Please upload a image and retry.')) + # return input_text, result_text elif input_text == "": result_text.append((input_text, 'Text empty! Please enter text and retry.')) return "", result_text request_para = {"temperature": temperature, "top_p": top_p} - image = Image.open(image_prompt) + if image_prompt is not None: + image = Image.open(image_prompt) + else: + image = None try: answer = generate_text_with_image(input_text, image, result_text.copy(), request_para, is_zh) except Exception as e: From c656e208975458d501a816b30fe5814925ae6e96 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 14:43:35 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_demo.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/web_demo.py b/web_demo.py index 79b0704..045ba82 100644 --- a/web_demo.py +++ b/web_demo.py @@ -3,8 +3,6 @@ import gradio as gr import requests from PIL import Image -import os -import json from model import is_chinese, get_infer_setting, generate_input, chat import torch From a20ae7f432706e833190e01521651d2523c003bb Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 15:03:19 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=88=96=E5=9B=BE=E7=89=87=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AF=E4=B8=80=E5=AE=9A=E5=BE=97=E8=87=B3=E5=B0=91=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web_demo.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/web_demo.py b/web_demo.py index 045ba82..b5b1929 100644 --- a/web_demo.py +++ b/web_demo.py @@ -35,15 +35,19 @@ def request_model(input_text, temperature, top_p, image_prompt, result_previous) print(f"history {result_text}") is_zh = is_chinese(input_text) - if image_prompt is None: - ... - # if is_zh: - # result_text.append((input_text, '图片为空!请上传图片并重试。')) - # else: - # result_text.append((input_text, 'Image empty! Please upload a image and retry.')) - # return input_text, result_text - elif input_text == "": - result_text.append((input_text, 'Text empty! Please enter text and retry.')) + # if image_prompt is None: + # ... + # if is_zh: + # result_text.append((input_text, '图片为空!请上传图片并重试。')) + # else: + # result_text.append((input_text, 'Image empty! Please upload a image and retry.')) + # return input_text, result_text + # elif input_text == "": + # result_text.append((input_text, 'Text empty! Please enter text and retry.')) + # return "", result_text + + if not (image_prompt or input_text): + result_text.append((input_text, 'Please enter text or/and upload a image, then retry.')) return "", result_text request_para = {"temperature": temperature, "top_p": top_p} From 16921c224f538a3f224d93ae659fe4d08985065c Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Thu, 13 Jul 2023 15:05:42 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1e566cc..58c92cb 100644 --- a/.gitignore +++ b/.gitignore @@ -162,4 +162,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -.run \ No newline at end of file +.run +test*.py \ No newline at end of file From e42a0eb069fa85614933467f7de7554497016c69 Mon Sep 17 00:00:00 2001 From: 90houlaoheshang <907333918@qq.com> Date: Mon, 17 Jul 2023 10:38:58 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E4=B8=8D=E5=B8=A6?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B9=9F=E5=8F=AF=E4=BB=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_hf.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/api_hf.py b/api_hf.py index fa1a635..caa7214 100644 --- a/api_hf.py +++ b/api_hf.py @@ -10,8 +10,9 @@ tokenizer = AutoTokenizer.from_pretrained("THUDM/visualglm-6b", trust_remote_code=True) model = AutoModel.from_pretrained("THUDM/visualglm-6b", trust_remote_code=True).half().cuda() - app = FastAPI() + + @app.post('/') async def visual_glm(request: Request): json_post_raw = await request.json() @@ -23,9 +24,13 @@ async def visual_glm(request: Request): history = request_data.get("history") image_encoded = request_data.get("image") query = request_data.get("text") - image_path = process_image(image_encoded) - with torch.no_grad(): + if image_encoded is not None: + image_path = process_image(image_encoded) + else: + image_path = '' + + with torch.no_grad(): result = model.stream_chat(tokenizer, image_path, query, history=history) last_result = None for value in result: @@ -46,4 +51,4 @@ async def visual_glm(request: Request): if __name__ == "__main__": - uvicorn.run(app, host='0.0.0.0', port=8080, workers=1) \ No newline at end of file + uvicorn.run(app, host='0.0.0.0', port=8080, workers=1)