satelliteapp / app.py
nchime's picture
Update app.py
84ac48d verified
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
model_name = "SJ-Donald/kcbert-large-unsmile"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
def classify_text(text):
"""
주어진 ν…μŠ€νŠΈκ°€ λΆ€μ μ ˆν•œμ§€ μ—¬λΆ€λ₯Ό νŒλ³„ν•©λ‹ˆλ‹€.
Args:
- text (str): νŒλ³„ν•  ν…μŠ€νŠΈ
Returns:
- result (str): 'λΆ€μ μ ˆν•œ λ‚΄μš©μ΄ ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.' or 'μ μ ˆν•œ λ‚΄μš©μž…λ‹ˆλ‹€.'
"""
results = classifier(text)
print(f"Debugging results: {results}") # κ²°κ³Ό ν™•μΈμš© 좜λ ₯
for result in results:
# λͺ¨λΈμ— 따라 라벨이 λ‹€λ₯Ό 수 μžˆμŠ΅λ‹ˆλ‹€.
if result['label'] == 'μ•…ν”Œ/μš•μ„€' and result['score'] > 0.5:
return "μ•…ν”Œ/μš•μ„€μž…λ‹ˆλ‹€."
elif result['label'] == 'μ—¬μ„±/κ°€μ‘±' and result['score'] > 0.5:
return "μ—¬μ„± ν˜μ˜€μž…λ‹ˆλ‹€"
elif result['label'] == '남성' and result['score'] > 0.5:
return "남성 ν˜μ˜€μž…λ‹ˆλ‹€"
elif result['label'] == '인쒅/ꡭ적' and result['score'] > 0.5:
return "인쒅/ꡭ적 ν˜μ˜€μž…λ‹ˆλ‹€"
elif result['label'] == 'μ—°λ Ή' and result['score'] > 0.5:
return "μ—°λ Ή ν˜μ˜€μž…λ‹ˆλ‹€"
elif result['label'] == '지역' and result['score'] > 0.5:
return "지역 ν˜μ˜€μž…λ‹ˆλ‹€"
elif result['label'] == '쒅ꡐ' and result['score'] > 0.5:
return "쒅ꡐ ν˜μ˜€μž…λ‹ˆλ‹€"
elif result['label'] == '기타 혐였' and result['score'] > 0.5:
return "기타 ν˜μ˜€μž…λ‹ˆλ‹€"
return "μ μ ˆν•œ λ‚΄μš©μž…λ‹ˆλ‹€."
demo = gr.Interface(fn=classify_text, inputs="textbox", title="λΆ€μ μ ˆ λ¬Έμž₯ κ²€μΆœκΈ°", theme="soft", description="κΈ°μ€€: μ—¬μ„±/κ°€μ‘±, 남성, μ„±μ†Œμˆ˜μž, 인쒅/ꡭ적, μ—°λ Ή, 지역, 쒅ꡐ, 기타 혐였, μ•…ν”Œ/μš•μ„€", outputs="textbox")
demo.launch()