4 / app.py
onlyrickroll's picture
Update app.py
7f36c66 verified
Raw History Blame Contribute Delete
966 Bytes
import gradio as gr
from llama_cpp import Llama
from huggingface_hub import hf_hub_download
import os
# 1. 下载模型(仅语言模型部分,不下载 mmproj)
print("正在下载模型...")
model_path = hf_hub_download(
repo_id="Qwen/Qwen3-VL-8B-Instruct-GGUF",
filename="Qwen3VL-8B-Instruct-Q4_K_M.gguf"
)
# 2. 初始化模型 (不带 chat_handler)
print("正在加载模型到内存...")
llm = Llama(
model_path=model_path,
n_ctx=2048,
n_threads=2
)
def respond(message, history):
# message 现在只是纯文本字符串
response = llm.create_chat_completion(
messages=[{"role": "user", "content": message}],
max_tokens=512
)
return response["choices"][0]["message"]["content"]
# 3. 启动极简对话界面
demo = gr.ChatInterface(respond)
if __name__ == "__main__":
# 再次强调:端口必须是 7860,否则 Docker Space 会挂掉
demo.launch(server_name="0.0.0.0", server_port=7860)