Spaces:
Runtime error
Runtime error
File size: 2,016 Bytes
3d9fdfd 8f8977c 3d9fdfd 7e3b6e0 3d9fdfd 52d58f7 3d9fdfd 52d58f7 3d9fdfd 2c289f8 8f8977c a9ced73 3d9fdfd eb530e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# ์ถ๋ก
from transformers import RobertaTokenizer, RobertaForSequenceClassification
import torch
import streamlit as st
# ์ ์ดํ์ต์ ์ฌ์ฉํ ํ ํฌ๋์ด์ ์ ๋ชจ๋ธ ๋ก๋ & ๊ฐ์ค์น ๋ก๋
tokenizer = RobertaTokenizer.from_pretrained('beomi/KcBERT-v2023')
model = RobertaForSequenceClassification.from_pretrained('beomi/KcBERT-v2023', num_labels=2)
model.load_state_dict(torch.load("pytorchmodel_518๋ง์ธ๋ถ๋ฅ_acc8583.bin", map_location=torch.device('cpu')))
# ๋ชจ๋ธ์ ํ๊ฐ ๋ชจ๋๋ก ์ค์
model.eval()
# ์
๋ ฅ ํ
์คํธ ์์
class_labels = ["๋ฌธ์ ์์/๊ด๋ จ์์", "๋ถ์ ์ (518 ๋ง์ธ ๊ฐ๋ฅ)"]
def inference(new_text):
inputs = tokenizer(new_text, return_tensors="pt")
# ์ถ๋ก ์ํ (CPU ์ฌ์ฉ)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=-1)
predicted_class = torch.argmax(probs, dim=1).item()
predicted_label = class_labels[predicted_class]
unpredicted_label = class_labels[1-predicted_class]
probability = probs[0][predicted_class].item()
return f"{predicted_label}:{probability*100:.2f}%, {unpredicted_label}:{((1-probability)*100):.2f}%"
# Streamlit interface
st.markdown('### 5ยท18 ๋ฏผ์ฃผํ์ด๋ ๊ด๋ จ ๋ถ์ ์ ํ ๋ฐ์ธ ํ๋จ(๋ฒ ํ๋ฒ์ )')
st.markdown('<small style="color:grey;">5ยท18 ๋ฏผ์ฃผํ์ด๋๊ณผ ๊ด๋ จํด ๋ฌด์ฅ ํญ๋, ๋ถํ๊ตฐ ๊ฐ์
, ๊ฐ์ง ์ ๊ณต์ ๋ฑ ๋ถ์ ์ ํ ์ธ๊ธ๊ณผ ์ง์ญ-์ด๋
์ ๋ํ ํ์ค์ฑ ๋ฐ์ธ์ด ๋ฌธ์ ๋๊ณ ์์ต๋๋ค. ์๋์ ๋ฌธ์ฅ์ ์
๋ ฅํ๋ฉด ์ด๋ฌํ ๋ด์ฉ์ ์ค์ฌ์ผ๋ก "๋ฌธ์ ์์/๊ด๋ จ์์" ๋๋ "๋ถ์ ์ (518 ๋ง์ธ ๊ฐ๋ฅ)"๋ก ํ๋จํด ๋๋ฆฝ๋๋ค. ์์ธก ๋ชจ๋ธ์ ์ ํ๋๋ 85.83%๋ก, ์ผ๋ถ ๋ถ์ ํํ ๊ฒฐ๊ณผ๊ฐ ๋์ฌ ์ ์์ต๋๋ค </small>', unsafe_allow_html=True)
user_input = st.text_area("์ด ๊ณณ์ ๋ฌธ์ฅ ์
๋ ฅ(100์ ์ดํ ๊ถ์ฅ, ๋๋ฌด ๊ธธ๋ฉด ๋ถ์ ๋ถ๊ฐ):")
if st.button('์์'):
result = inference(user_input)
st.write(result) |