YLX1965 commited on
Commit
7a137aa
·
verified ·
1 Parent(s): 7a6d53d

update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,13 +1,23 @@
 
 
1
  from llama_cpp import Llama
 
 
 
 
 
2
 
3
- # 直接从 Hugging Face 加载模型(避免存储问题)
4
- llm = Llama.from_pretrained("YLX1965/medical-model", filename="unsloth.Q8_0.gguf")
5
 
 
 
 
 
6
  def chat(prompt):
7
  output = llm(prompt, max_tokens=200)
8
  return output["choices"][0]["text"]
9
 
10
  # 运行 Gradio
11
- import gradio as gr
12
  interface = gr.Interface(fn=chat, inputs="text", outputs="text")
13
  interface.launch()
 
1
+ import os
2
+ from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
+ import gradio as gr
5
+
6
+ # 确保模型存储路径
7
+ model_dir = "/home/user/models"
8
+ os.makedirs(model_dir, exist_ok=True)
9
 
10
+ # 下载 GGUF 模型
11
+ model_path = hf_hub_download(repo_id="YLX1965/medical-model", filename="unsloth.Q8_0.gguf", cache_dir=model_dir)
12
 
13
+ # 加载 GGUF 模型
14
+ llm = Llama(model_path=model_path)
15
+
16
+ # 定义聊天函数
17
  def chat(prompt):
18
  output = llm(prompt, max_tokens=200)
19
  return output["choices"][0]["text"]
20
 
21
  # 运行 Gradio
 
22
  interface = gr.Interface(fn=chat, inputs="text", outputs="text")
23
  interface.launch()