Pisethan commited on
Commit
b1b79a6
Β·
verified Β·
1 Parent(s): 7e624c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -1,21 +1,36 @@
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()
 
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()