Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Load
|
5 |
classifier = pipeline("text-classification", model="Pisethan/khmer-classifier")
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def predict(text):
|
8 |
output = classifier(text)[0]
|
9 |
-
|
|
|
|
|
10 |
|
11 |
demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="Khmer Prompt Classifier")
|
12 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load classifier
|
5 |
classifier = pipeline("text-classification", model="Pisethan/khmer-classifier")
|
6 |
|
7 |
+
# Map model label IDs to real names
|
8 |
+
label_map = {
|
9 |
+
"LABEL_0": "count_boys",
|
10 |
+
"LABEL_1": "grade2_lesson",
|
11 |
+
"LABEL_2": "most_students"
|
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 |
demo = gr.Interface(fn=predict, inputs="text", outputs="text", title="Khmer Prompt Classifier")
|
21 |
demo.launch()
|