update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,23 @@
|
|
|
|
|
|
1 |
from llama_cpp import Llama
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
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()
|