Error Lover commited on
Commit
79276d7
·
1 Parent(s): 450f3fe

Add application file

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import joblib
3
+ import gradio as gr
4
+ from sentence_transformers import SentenceTransformer
5
+
6
+ enc = SentenceTransformer("all-MiniLM-L6-v2")
7
+ clf = joblib.load("model.pkl")
8
+ meta = joblib.load("meta.pkl")
9
+ threshold = meta["threshold"]
10
+
11
+ EXAMPLES = [
12
+ ["What is 2 + 2?"],
13
+ ["Write a Python function to reverse a linked list."],
14
+ ["Explain how transformers handle long-range dependencies in NLP."],
15
+ ["What microscopic mechanisms reconcile correlated insulating phases with unconventional superconductivity in magic-angle twisted bilayer graphene?"],
16
+ ]
17
+
18
+ def predict(q):
19
+ if not q.strip():
20
+ return "—", "—"
21
+ emb = enc.encode([q])
22
+ prob = clf.predict_proba(emb)[0][1] # prob of "complex"
23
+ label = "🔴 Complex" if prob > 0.5 else "🟢 Simple"
24
+ confidence = f"{max(prob, 1-prob):.1%}"
25
+ return label, confidence
26
+
27
+ with gr.Blocks(title="Question Complexity Classifier") as demo:
28
+ gr.Markdown(
29
+ """
30
+ # 🧠 Question Complexity Classifier
31
+ Predicts whether a question requires **long chain-of-thought reasoning** or not.
32
+ Trained on 20k samples from [KIMI-K2.5-700000x](https://huggingface.co/datasets/ianncity/KIMI-K2.5-700000x) reasoning traces.
33
+ Complexity proxy: CoT length > {:.0f} chars = Complex.
34
+ """.format(threshold)
35
+ )
36
+
37
+ with gr.Row():
38
+ inp = gr.Textbox(label="Question", lines=4, placeholder="Enter any question...")
39
+ with gr.Column():
40
+ out_label = gr.Textbox(label="Complexity")
41
+ out_conf = gr.Textbox(label="Confidence")
42
+
43
+ btn = gr.Button("Predict", variant="primary")
44
+ btn.click(predict, inputs=inp, outputs=[out_label, out_conf])
45
+ inp.submit(predict, inputs=inp, outputs=[out_label, out_conf])
46
+
47
+ gr.Examples(examples=EXAMPLES, inputs=inp, label="Try these")
48
+
49
+ demo.launch()