onlyrickroll commited on
Commit
476a62c
·
verified ·
1 Parent(s): aabc23d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -33
app.py CHANGED
@@ -1,34 +1,34 @@
1
- import gradio as gr
2
- from llama_cpp import Llama
3
- from huggingface_hub import hf_hub_download
4
- import os
5
-
6
- # 1. 下载模型(仅语言模型部分,不下载 mmproj)
7
- print("正在下载模型...")
8
- model_path = hf_hub_download(
9
- repo_id="Qwen/Qwen2.5-VL-8B-Instruct-GGUF",
10
- filename="Qwen2.5-VL-8B-Instruct-Q4_K_M.gguf"
11
- )
12
-
13
- # 2. 初始化模型 (不带 chat_handler)
14
- print("正在加载模型到内存...")
15
- llm = Llama(
16
- model_path=model_path,
17
- n_ctx=2048,
18
- n_threads=4
19
- )
20
-
21
- def respond(message, history):
22
- # message 现在只是纯文本字符串
23
- response = llm.create_chat_completion(
24
- messages=[{"role": "user", "content": message}],
25
- max_tokens=512
26
- )
27
- return response["choices"][0]["message"]["content"]
28
-
29
- # 3. 启动极简对话界面
30
- demo = gr.ChatInterface(respond)
31
-
32
- if __name__ == "__main__":
33
- # 再次强调:端口必须是 7860,否则 Docker Space 会挂掉
34
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ import gradio as gr
2
+ from llama_cpp import Llama
3
+ from huggingface_hub import hf_hub_download
4
+ import os
5
+
6
+ # 1. 下载模型(仅语言模型部分,不下载 mmproj)
7
+ print("正在下载模型...")
8
+ model_path = hf_hub_download(
9
+ repo_id="Qwen/Qwen3-VL-8B-Instruct-GGUF",
10
+ filename="Qwen3-VL-8B-Instruct-Q4_K_M.gguf"
11
+ )
12
+
13
+ # 2. 初始化模型 (不带 chat_handler)
14
+ print("正在加载模型到内存...")
15
+ llm = Llama(
16
+ model_path=model_path,
17
+ n_ctx=2048,
18
+ n_threads=4
19
+ )
20
+
21
+ def respond(message, history):
22
+ # message 现在只是纯文本字符串
23
+ response = llm.create_chat_completion(
24
+ messages=[{"role": "user", "content": message}],
25
+ max_tokens=512
26
+ )
27
+ return response["choices"][0]["message"]["content"]
28
+
29
+ # 3. 启动极简对话界面
30
+ demo = gr.ChatInterface(respond)
31
+
32
+ if __name__ == "__main__":
33
+ # 再次强调:端口必须是 7860,否则 Docker Space 会挂掉
34
  demo.launch(server_name="0.0.0.0", server_port=7860)