My Code:
import streamlit as st
from diffusers import CogView4Pipeline
import torch
st.set_page_config(
page_title="CogView绘图工具",
layout="wide")
st.title("CogView绘图工具")
model_dir = r"D:\AI\CogView4\CogView4-6B"
pipe = CogView4Pipeline.from_pretrained(model_dir, torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
pipe.vae.enable_slicing()
pipe.vae.enable_tiling()
with st.form("my_form"):
st.write("请输入提示词:")
prompt = st.text_area("Prompt:", value="秋季的长城,植被呈现出红、黄、绿等多种色彩,与蜿蜒的城墙、起伏的山峦相互交织,构成了一幅层次分明、色彩丰富的自然景观画面。画面上方是汉字:不到长城非好汉")
button = st.form_submit_button(label="提交",use_container_width=False)
if button:
with st.spinner("正在生成图片..."):
c1, c2, c3 = st.columns([1, 2, 1])
with c1:
st.empty()
with c2:
image = pipe(
prompt=prompt,
guidance_scale=3.5,
num_images_per_prompt=1,
num_inference_steps=50,
width=1024,
height=1024,
).images[0]
st.image(image, caption="CogView4绘图结果")
st.success("cogview4-4.png生成成功!")
with c3:
st.empty()
after run :
streamlit run app.py
I got this:
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 3/3 [00:00<00:00, 40.41it/s]
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:00<00:00, 4.55it/s]
Loading pipeline components...: 100%|████████████████████████████████████████████████████| 5/5 [00:02<00:00, 2.06it/s]
2025-03-05 21:16:49.382 Examining the path of torch.classes raised:
Traceback (most recent call last):
File "D:\AI\CogView4\env-cogview\Lib\site-packages\streamlit\web\bootstrap.py", line 345, in run
if asyncio.get_running_loop().is_running():
^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: no running event loop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\AI\CogView4\env-cogview\Lib\site-packages\streamlit\watcher\local_sources_watcher.py", line 217, in get_module_paths
potential_paths = extract_paths(module)
^^^^^^^^^^^^^^^^^^^^^
File "D:\AI\CogView4\env-cogview\Lib\site-packages\streamlit\watcher\local_sources_watcher.py", line 210, in <lambda>
lambda m: list(m.__path__._path),
^^^^^^^^^^^^^^^^
File "D:\AI\CogView4\env-cogview\Lib\site-packages\torch\_classes.py", line 13, in __getattr__
proxy = torch._C._get_custom_class_python_wrapper(self.name, attr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Tried to instantiate class '__path__._path', but it does not exist! Ensure that it is registered via torch::class_
My pip list:
Package Version
------------------------- ------------
accelerate 1.4.0
altair 5.5.0
attrs 25.1.0
blinker 1.9.0
cachetools 5.5.2
certifi 2025.1.31
charset-normalizer 3.4.1
click 8.1.8
colorama 0.4.6
diffusers 0.33.0.dev0
diffusers 0.33.0.dev0
filelock 3.17.0
fsspec 2025.2.0
gitdb 4.0.12
GitPython 3.1.44
huggingface-hub 0.29.1
idna 3.10
importlib_metadata 8.6.1
Jinja2 3.1.5
jsonschema 4.23.0
jsonschema-specifications 2024.10.1
markdown-it-py 3.0.0
MarkupSafe 3.0.2
mdurl 0.1.2
mpmath 1.3.0
narwhals 1.29.0
networkx 3.4.2
numpy 2.2.3
packaging 24.2
pandas 2.2.3
pillow 11.1.0
pip 25.0.1
protobuf 5.29.3
psutil 7.0.0
pyarrow 19.0.1
pydeck 0.9.1
Pygments 2.19.1
python-dateutil 2.9.0.post0
pytz 2025.1
PyYAML 6.0.2
referencing 0.36.2
regex 2024.11.6
requests 2.32.3
rich 13.9.4
rpds-py 0.23.1
safetensors 0.5.3
setuptools 65.5.0
six 1.17.0
smmap 5.0.2
streamlit 1.43.0
sympy 1.13.1
tenacity 9.0.0
tokenizers 0.21.0
toml 0.10.2
torch 2.6.0+cu126
torchaudio 2.6.0+cu126
torchvision 0.21.0+cu126
tornado 6.4.2
tqdm 4.67.1
transformers 4.49.0
typing_extensions 4.12.2
tzdata 2025.1
urllib3 2.3.0
watchdog 6.0.0
zipp 3.21.0