Spaces:
Paused
Paused
Download app.py from onlyrickroll/4: direct link, hf CLI and curl.
- Browser
- Download file 966 Bytes
-
https://huggingface.co/spaces/onlyrickroll/4/resolve/main/app.py
- Command line
-
hf download hf://spaces/onlyrickroll/4/app.py
-
curl -L -o app.py https://huggingface.co/spaces/onlyrickroll/4/resolve/main/app.py
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) |