File size: 1,183 Bytes
d0afe25
 
 
b1b79a6
d0afe25
 
b1b79a6
7e624c3
b1b79a6
7e624c3
b1b79a6
7e624c3
 
b1b79a6
d0afe25
 
7e624c3
 
 
d0afe25
b1b79a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0afe25
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
35
36
37
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()