VisualGLM-6B icon indicating copy to clipboard operation
VisualGLM-6B copied to clipboard

运行web_demo_hf.py时遇到tmp文件写入被拒的问题

Open yangxingrui opened this issue 1 year ago • 2 comments

跑cli_demo_hf.py命令行界面运行良好,但运行web版本时发现,提交任何文本都不会响应,后经过摸索发现,gradio模块的访问临时文件被服务器拒绝,请问有什么解决方案 image

yangxingrui avatar May 20 '23 09:05 yangxingrui

gradio 的文件映射由 tempfile._TemporaryFileWrapper 实现, 请在shell中尝试:

> python
import tempfile
tempfile.gettempdir()

预期输出为

/tmp/

你可以选择在代码中加入:

tempfile.tempdir = "./tmp"

来临时将 tempfile 制定到项目根目录,或者其他你有权限的位置

tuteng0915 avatar May 20 '23 12:05 tuteng0915

非常棒,你的办法有效,感谢你的解答

yangxingrui avatar May 20 '23 14:05 yangxingrui

tempfile.tempdir = "./tmp"

你好,我用了你说的方法,但是一直报FileNotFoundError,创建了文件夹后又报新的: FileNotFoundError [Errno 2] No such file or directory: './tmp/tmpg4o6naoc'

Lukangkang123 avatar Jun 09 '23 01:06 Lukangkang123

tempfile.tempdir = "./tmp"

你好,我用了你说的方法,但是一直报FileNotFoundError,创建了文件夹后又报新的: FileNotFoundError [Errno 2] No such file or directory: './tmp/tmpg4o6naoc'

from transformers import AutoModel, AutoTokenizer
import gradio as gr
import mdtex2html
import tempfile
import os
os.makedirs("./tmp", exist_ok=True)
tempfile.tempdir = "./tmp"

tokenizer = AutoTokenizer.from_pretrained("model/chatglm-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("model/chatglm-6b", trust_remote_code=True).half().cuda()
model = model.eval()

这样试试呢

Assassin-King avatar Dec 06 '23 07:12 Assassin-King