YLX1965 commited on
Commit
14ac0de
·
verified ·
1 Parent(s): 4d880c5

update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -1,11 +1,31 @@
1
  import gradio as gr
 
 
2
  from llama_cpp import Llama
3
 
4
- # 加载 GGUF 模型(替换成你的模型路径)
5
- model_path = "YLX1965/medical-model/unsloth.Q8_0.gguf"
 
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  llm = Llama(model_path=model_path)
8
 
 
9
  def chat(prompt):
10
  output = llm(prompt, max_tokens=200)
11
  return output["choices"][0]["text"]
 
1
  import gradio as gr
2
+ import os
3
+ import requests
4
  from llama_cpp import Llama
5
 
6
+ # 确保模型文件夹存在
7
+ model_dir = "/home/user/models"
8
+ os.makedirs(model_dir, exist_ok=True)
9
 
10
+ # GGUF 模型文件名
11
+ model_name = "unsloth.Q8_0.gguf"
12
+ model_path = os.path.join(model_dir, model_name)
13
+
14
+ # 如果模型文件不存在,则从 Hugging Face 下载
15
+ hf_model_url = "https://huggingface.co/YLX1965/medical-model/resolve/main/unsloth.Q8_0.gguf"
16
+
17
+ if not os.path.exists(model_path):
18
+ print(f"Downloading model from {hf_model_url}...")
19
+ response = requests.get(hf_model_url, stream=True)
20
+ with open(model_path, "wb") as f:
21
+ for chunk in response.iter_content(chunk_size=8192):
22
+ f.write(chunk)
23
+ print("Download complete.")
24
+
25
+ # 加载 GGUF 模型
26
  llm = Llama(model_path=model_path)
27
 
28
+ # 定义聊天函数
29
  def chat(prompt):
30
  output = llm(prompt, max_tokens=200)
31
  return output["choices"][0]["text"]