Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
classifier = pipeline("text-classification", model="Pisethan/khmer-classifier")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
label_map = {
|
| 9 |
-
"LABEL_0": "
|
| 10 |
"LABEL_1": "grade2_lesson",
|
| 11 |
-
"LABEL_2": "
|
| 12 |
}
|
| 13 |
|
|
|
|
| 14 |
def predict(text):
|
| 15 |
output = classifier(text)[0]
|
| 16 |
label_id = output["label"]
|
| 17 |
label_name = label_map.get(label_id, label_id)
|
| 18 |
return f"π Label: {label_name} (Score: {output['score']:.2f})"
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the fine-tuned model from Hugging Face Hub
|
| 5 |
classifier = pipeline("text-classification", model="Pisethan/khmer-classifier")
|
| 6 |
|
| 7 |
+
# Label mapping (match this to your training label order)
|
| 8 |
label_map = {
|
| 9 |
+
"LABEL_0": "most_students",
|
| 10 |
"LABEL_1": "grade2_lesson",
|
| 11 |
+
"LABEL_2": "count_boys"
|
| 12 |
}
|
| 13 |
|
| 14 |
+
# Define prediction function
|
| 15 |
def predict(text):
|
| 16 |
output = classifier(text)[0]
|
| 17 |
label_id = output["label"]
|
| 18 |
label_name = label_map.get(label_id, label_id)
|
| 19 |
return f"π Label: {label_name} (Score: {output['score']:.2f})"
|
| 20 |
|
| 21 |
+
# Build Gradio interface
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=predict,
|
| 24 |
+
inputs=gr.Textbox(label="Khmer Question"),
|
| 25 |
+
outputs=gr.Textbox(label="Predicted Label"),
|
| 26 |
+
title="Khmer Prompt Classifier",
|
| 27 |
+
description="π§ Enter a Khmer question and get the predicted category.",
|
| 28 |
+
examples=[
|
| 29 |
+
["αα·αααααααΆααααΈα’ααααΌααααα’αααΈ?"],
|
| 30 |
+
["ααΎααΆααα·ααααααα»αααα»ααααΆαααΆαα?"],
|
| 31 |
+
["ααΆααΆααΆααΆααα·αααα
αααΎαααΆααα?"]
|
| 32 |
+
]
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch
|
| 36 |
demo.launch()
|