yava-code/question-complexity
0
1import re2import joblib3import gradio as gr4from sentence_transformers import SentenceTransformer5 6enc = SentenceTransformer("all-MiniLM-L6-v2")7clf = joblib.load("model.pkl")8meta = joblib.load("meta.pkl")9threshold = meta["threshold"]10 11EXAMPLES = [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 18def 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, confidence26 27with gr.Blocks(title="Question Complexity Classifier") as demo:28 gr.Markdown(29 """30# 🧠 Question Complexity Classifier31Predicts whether a question requires **long chain-of-thought reasoning** or not. 32Trained on 20k samples from [KIMI-K2.5-700000x](https://huggingface.co/datasets/ianncity/KIMI-K2.5-700000x) reasoning traces. 33Complexity 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 49demo.launch()50 