4
File size: 966 Bytes
476a62c
 
 
 
 
 
 
 
 
f26f149
476a62c
 
 
 
 
 
 
7f36c66
476a62c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aabc23d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)