Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load the fine-tuned model from Hugging Face Hub | |
classifier = pipeline("text-classification", model="Pisethan/khmer-classifier") | |
# Label mapping (match this to your training label order) | |
label_map = { | |
"LABEL_0": "most_students", | |
"LABEL_1": "grade2_lesson", | |
"LABEL_2": "count_boys" | |
} | |
# Define prediction function | |
def predict(text): | |
output = classifier(text)[0] | |
label_id = output["label"] | |
label_name = label_map.get(label_id, label_id) | |
return f"π Label: {label_name} (Score: {output['score']:.2f})" | |
# Build Gradio interface | |
demo = gr.Interface( | |
fn=predict, | |
inputs=gr.Textbox(label="Khmer Question"), | |
outputs=gr.Textbox(label="Predicted Label"), | |
title="Khmer Prompt Classifier", | |
description="π§ Enter a Khmer question and get the predicted category.", | |
examples=[ | |
["αα·αααααααΆααααΈα’ααααΌααααα’αααΈ?"], | |
["ααΎααΆααα·ααααααα»αααα»ααααΆαααΆαα?"], | |
["ααΆααΆααΆααΆααα·αααα αααΎαααΆααα?"] | |
] | |
) | |
# Launch | |
demo.launch() | |