Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,22 @@
|
|
| 1 |
-
import
|
| 2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# 处理输入的函数
|
| 13 |
def predict(symptoms):
|
| 14 |
try:
|
| 15 |
-
# 对输入的症状进行
|
| 16 |
inputs = tokenizer(symptoms, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 17 |
with torch.no_grad():
|
| 18 |
# 模型推理
|
|
@@ -39,3 +43,4 @@ gr.Interface(
|
|
| 39 |
description="通过输入症状,预测可能的疾病和推荐科室。",
|
| 40 |
).launch(debug=True)
|
| 41 |
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
# 从环境变量中获取 Token
|
| 7 |
+
token = os.getenv("HF_TOKEN") # 获取在 Hugging Face Secrets 中设置的 "HF_TOKEN"
|
| 8 |
|
| 9 |
+
# 模型 ID
|
| 10 |
+
repo_id = "huohuo828/bishe"
|
| 11 |
+
|
| 12 |
+
# 加载模型和 tokenizer
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id, use_auth_token=token)
|
| 14 |
+
model = AutoModelForSequenceClassification.from_pretrained(repo_id, use_auth_token=token)
|
| 15 |
|
| 16 |
# 处理输入的函数
|
| 17 |
def predict(symptoms):
|
| 18 |
try:
|
| 19 |
+
# 对输入的症状进行 tokenization
|
| 20 |
inputs = tokenizer(symptoms, return_tensors="pt", padding=True, truncation=True, max_length=512)
|
| 21 |
with torch.no_grad():
|
| 22 |
# 模型推理
|
|
|
|
| 43 |
description="通过输入症状,预测可能的疾病和推荐科室。",
|
| 44 |
).launch(debug=True)
|
| 45 |
|
| 46 |
+
|