naveenus commited on
Commit
b90e13b
·
verified ·
1 Parent(s): 210ad19

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # 1) Initialize zero-shot classifier
5
+ classifier = pipeline(
6
+ task="zero-shot-classification",
7
+ model="facebook/bart-large-mnli"
8
+ )
9
+
10
+ # 2) Define candidate labels
11
+ LABELS = ["linear algebra", "calculus", "probability", "geometry"]
12
+
13
+ # 3) Gradio interface function
14
+ def tag_question(question):
15
+ result = classifier(question, candidate_labels=LABELS)
16
+ return {lbl: round(score, 3) for lbl, score in zip(result["labels"], result["scores"])}
17
+
18
+ # 4) Build UI
19
+ iface = gr.Interface(
20
+ fn=tag_question,
21
+ inputs=gr.Textbox(lines=3, placeholder="Enter your MCQ here..."),
22
+ outputs=gr.Label(num_top_classes=3),
23
+ title="Zero-Shot Question Tagger",
24
+ description="Classify questions into math topics without any training data."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()