Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# ๋ชจ๋ธ ๋ก๋ฉ (HuggingFace์ havocy28/VetBERT ์ฌ์ฉ)
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("havocy28/VetBERT")
|
| 7 |
+
model = AutoModelForSequenceClassification.from_pretrained("havocy28/VetBERT")
|
| 8 |
+
|
| 9 |
+
def classify_symptom(text):
|
| 10 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 11 |
+
with torch.no_grad():
|
| 12 |
+
logits = model(**inputs).logits
|
| 13 |
+
pred = torch.argmax(logits, dim=1).item()
|
| 14 |
+
|
| 15 |
+
# ์์ ๋ ์ด๋ธ ์ด๋ฆ (๋ชจ๋ธ์ ๋ง์ถฐ ์์ ๊ฐ๋ฅ)
|
| 16 |
+
labels = {
|
| 17 |
+
0: "์ ์",
|
| 18 |
+
1: "์ํ๊ธฐ ์งํ",
|
| 19 |
+
2: "ํธํก๊ธฐ ์งํ",
|
| 20 |
+
3: "ํผ๋ถ ์งํ",
|
| 21 |
+
4: "๊ธฐํ ์ด์",
|
| 22 |
+
}
|
| 23 |
+
return labels.get(pred, f"์์ธก ๋ผ๋ฒจ: {pred}")
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=classify_symptom,
|
| 27 |
+
inputs=gr.Textbox(lines=3, placeholder="๋ฐ๋ ค๋๋ฌผ ์ฆ์์ ์
๋ ฅํด์ฃผ์ธ์."),
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="VetBERT AI ์์์ฌ",
|
| 30 |
+
description="๋ฐ๋ ค๊ฒฌ/๋ฌ ์ฆ์ ๋ฌธ์ฅ์ ์
๋ ฅํ๋ฉด AI๊ฐ ์์ฌ ์ง๋ณ์ ๋ถ๋ฅํด์ค๋๋ค."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|