Spaces:
Sleeping
Sleeping
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() | |