File size: 837 Bytes
b90e13b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# 1) Initialize zero-shot classifier
classifier = pipeline(
    task="zero-shot-classification",
    model="facebook/bart-large-mnli"
)

# 2) Define candidate labels
LABELS = ["linear algebra", "calculus", "probability", "geometry"]

# 3) Gradio interface function
def tag_question(question):
    result = classifier(question, candidate_labels=LABELS)
    return {lbl: round(score, 3) for lbl, score in zip(result["labels"], result["scores"])}

# 4) Build UI
iface = gr.Interface(
    fn=tag_question,
    inputs=gr.Textbox(lines=3, placeholder="Enter your MCQ here..."),
    outputs=gr.Label(num_top_classes=3),
    title="Zero-Shot Question Tagger",
    description="Classify questions into math topics without any training data."
)

if __name__ == "__main__":
    iface.launch()