yuvraj-yadav commited on
Commit
c02e09b
·
verified ·
1 Parent(s): 5d0f2b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ from sentence_transformers import SentenceTransformer
4
+ from sklearn.metrics.pairwise import cosine_similarity
5
+ import gradio as gr
6
+
7
+ # Load fast transformer model
8
+ model = SentenceTransformer('all-MiniLM-L6-v2') # Faster & free
9
+
10
+ # Define math domains and descriptions
11
+ DOMAINS = {
12
+ "Real Analysis": "Studies properties of real-valued functions, sequences, limits, continuity, differentiation, Riemann/ Lebesgue integration, and convergence in the real number system.",
13
+ "Complex Analysis": "Explores analytic functions of complex variables, contour integration, conformal mappings, and singularity theory.",
14
+ "Functional Analysis": "Deals with infinite-dimensional vector spaces, Banach and Hilbert spaces, linear operators, duality, and spectral theory in the context of functional spaces.",
15
+ "Measure Theory": "Studies sigma-algebras, measures, measurable functions, and integrals, forming the foundation for modern probability and real analysis.",
16
+ "Fourier and Harmonic Analysis": "Analyzes functions via decompositions into sines, cosines, or general orthogonal bases, often involving Fourier series, Fourier transforms, and convolution techniques.",
17
+ "Calculus of Variations": "Optimizes functionals over infinite-dimensional spaces, leading to Euler-Lagrange equations and applications in physics and control theory.",
18
+ "Metric Geometry": "Explores geometric properties of metric spaces and the behavior of functions and sequences under various notions of distance.",
19
+ "Ordinary Differential Equations (ODEs)": "Involves differential equations with functions of a single variable, their qualitative behavior, existence, uniqueness, and methods of solving them.",
20
+ "Partial Differential Equations (PDEs)": "Deals with multivariable functions involving partial derivatives, including wave, heat, and Laplace equations.",
21
+ "Dynamical Systems": "Studies evolution of systems over time using discrete or continuous-time equations, stability theory, phase portraits, and attractors.",
22
+ "Linear Algebra": "Focuses on vector spaces, linear transformations, eigenvalues, diagonalization, and matrices.",
23
+ "Abstract Algebra": "General study of algebraic structures such as groups, rings, fields, and modules.",
24
+ "Group Theory": "Investigates algebraic structures with a single binary operation satisfying group axioms, including symmetry groups and applications.",
25
+ "Ring and Module Theory": "Extends group theory to rings (two operations) and modules (generalized vector spaces).",
26
+ "Field Theory": "Studies field extensions, algebraic and transcendental elements, and classical constructions.",
27
+ "Galois Theory": "Connects field theory and group theory to solve polynomial equations and understand solvability.",
28
+ "Algebraic Number Theory": "Applies tools from abstract algebra to study integers, Diophantine equations, and number fields.",
29
+ "Representation Theory": "Studies abstract algebraic structures by representing their elements as linear transformations of vector spaces.",
30
+ "Algebraic Geometry": "Examines solutions to polynomial equations using geometric and algebraic techniques like varieties, schemes, and morphisms.",
31
+ "Differential Geometry": "Studies geometric structures on smooth manifolds, curvature, geodesics, and applications in general relativity.",
32
+ "Topology": "Analyzes qualitative spatial properties preserved under continuous deformations, including homeomorphism, compactness, and connectedness.",
33
+ "Geometric Topology": "Explores topological manifolds and their classification, knot theory, and low-dimensional topology.",
34
+ "Symplectic Geometry": "Studies geometry arising from Hamiltonian systems and phase space, central to classical mechanics.",
35
+ "Combinatorics": "Covers enumeration, existence, construction, and optimization of discrete structures.",
36
+ "Graph Theory": "Deals with the study of graphs, networks, trees, connectivity, and coloring problems.",
37
+ "Discrete Geometry": "Focuses on geometric objects and combinatorial properties in finite settings, such as polytopes and tilings.",
38
+ "Set Theory": "Studies sets, cardinality, ordinals, ZFC axioms, and independence results.",
39
+ "Mathematical Logic": "Includes propositional logic, predicate logic, proof theory, model theory, and recursion theory.",
40
+ "Category Theory": "Provides a high-level, structural framework to relate different mathematical systems through morphisms and objects.",
41
+ "Probability Theory": "Mathematical foundation for randomness, including random variables, distributions, expectation, and stochastic processes.",
42
+ "Mathematical Statistics": "Theory behind estimation, hypothesis testing, confidence intervals, and likelihood inference.",
43
+ "Stochastic Processes": "Studies processes that evolve with randomness over time, like Markov chains and Brownian motion.",
44
+ "Information Theory": "Analyzes data transmission, entropy, coding theory, and information content in probabilistic settings.",
45
+ "Numerical Analysis": "Designs and analyzes algorithms to approximate solutions of mathematical problems including root-finding, integration, and differential equations.",
46
+ "Optimization": "Studies finding best outcomes under constraints, including convex optimization, linear programming, and integer programming.",
47
+ "Operations Research": "Applies optimization, simulation, and probabilistic modeling to decision-making problems in logistics, finance, and industry.",
48
+ "Control Theory": "Mathematically models and regulates dynamic systems through feedback and optimal control strategies.",
49
+ "Computational Mathematics": "Applies algorithmic and numerical techniques to solve mathematical problems on computers.",
50
+ "Game Theory": "Analyzes strategic interaction among rational agents using payoff matrices and equilibrium concepts.",
51
+ "Machine Learning Theory": "Explores the mathematical foundation of algorithms that learn from data, covering generalization, VC dimension, and convergence.",
52
+ "Spectral Theory": "Studies the spectrum (eigenvalues) of linear operators, primarily in Hilbert/Banach spaces, relevant to quantum mechanics and PDEs.",
53
+ "Operator Theory": "Focuses on properties of linear operators on function spaces and their classification.",
54
+ "Mathematical Physics": "Uses advanced mathematical tools to solve and model problems in physics, often involving differential geometry and functional analysis.",
55
+ "Financial Mathematics": "Applies stochastic calculus and optimization to problems in pricing, risk, and investment.",
56
+ "Mathematics Education": "Focuses on teaching methods, learning theories, and curriculum design in mathematics.",
57
+ "History of Mathematics": "Studies the historical development of mathematical concepts, theorems, and personalities.",
58
+ "Others / Multidisciplinary": "Covers problems that span multiple mathematical areas or do not fall neatly into a traditional domain."
59
+ }
60
+
61
+ domain_names = list(DOMAINS.keys())
62
+ domain_texts = list(DOMAINS.values())
63
+ domain_embeddings = model.encode(domain_texts)
64
+
65
+ def classify_math_question(question):
66
+ q_embed = model.encode([question])
67
+ scores = cosine_similarity(q_embed, domain_embeddings)[0]
68
+ sorted_indices = scores.argsort()[::-1]
69
+ major = domain_names[sorted_indices[0]]
70
+ minor = domain_names[sorted_indices[1]]
71
+ major_reason = DOMAINS[major]
72
+ minor_reason = DOMAINS[minor]
73
+ explanation = f"**Major Domain:** {major}\\n\\n*Reason:* {major_reason}\\n\\n" + \\
74
+ f"**Minor Domain:** {minor}\\n\\n*Reason:* {minor_reason}"
75
+ return explanation
76
+
77
+ iface = gr.Interface(
78
+ fn=classify_math_question,
79
+ inputs=gr.Textbox(lines=4, placeholder="Enter a math question..."),
80
+ outputs="textbox",
81
+ title="🔍 Math Domain Classifier (Major + Minor)",
82
+ description="Enter a math problem or statement, and get its major and minor domain with reasoning."
83
+ )
84
+
85
+ iface.launch()