bookdabang commited on
Commit
f165ab3
ยท
verified ยท
1 Parent(s): 0af66a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
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()