update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,13 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import os
|
3 |
-
import requests
|
4 |
from llama_cpp import Llama
|
5 |
|
6 |
-
#
|
7 |
-
|
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"]
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
description="使用 GGUF 量化模型进行医疗文本生成")
|
37 |
-
|
38 |
interface.launch()
|
|
|
|
|
|
|
|
|
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()
|