yuvraj-yadav commited on
Commit
026dc36
·
verified ·
1 Parent(s): 270cd6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -33
app.py CHANGED
@@ -65,31 +65,12 @@ domain_names = list(DOMAINS.keys())
65
  domain_texts = list(DOMAINS.values())
66
  domain_embeddings = model.encode(domain_texts)
67
 
68
- # Semantic Scholar + arXiv wrapper
69
- sch = SemanticScholar()
70
-
71
- def fetch_semantic_and_arxiv(query, top_n=5):
72
- papers = []
73
-
74
- # Semantic Scholar
75
- try:
76
- sem_results = sch.search_paper(query, limit=top_n)
77
- for p in sem_results:
78
- papers.append({
79
- "title": p.title,
80
- "authors": ", ".join(a.name for a in p.authors[:3]),
81
- "year": p.year,
82
- "url": p.url,
83
- "source": "Semantic Scholar"
84
- })
85
- except:
86
- pass
87
-
88
- # arXiv
89
  try:
90
- search = arxiv.Search(query=query, max_results=top_n)
91
  for r in search.results():
92
- papers.append({
93
  "title": r.title,
94
  "authors": ", ".join(a.name for a in r.authors[:3]),
95
  "year": r.published.year,
@@ -98,10 +79,9 @@ def fetch_semantic_and_arxiv(query, top_n=5):
98
  })
99
  except:
100
  pass
 
101
 
102
- return papers
103
-
104
- def fetch_duckduckgo_links(query, max_results=5):
105
  links = []
106
  try:
107
  with DDGS() as ddgs:
@@ -129,19 +109,19 @@ def classify_math_question(question):
129
  out = f"<b>Major Domain:</b> {major}<br><i>Reason:</i> {major_reason}<br><br>"
130
  out += f"<b>Minor Domain:</b> {minor}<br><i>Reason:</i> {minor_reason}<br><br>"
131
 
132
- refs = fetch_semantic_and_arxiv(question)
133
- links = fetch_duckduckgo_links(question)
134
 
135
  if refs:
136
- out += "<b>Top Academic References:</b><ul>"
137
  for p in refs:
138
- out += f"<li><b>{p['title']}</b> ({p['year']}) - <i>{p['authors']}</i> [{p['source']}]<br><a href='{p['url']}' target='_blank'>{p['url']}</a></li>"
139
  out += "</ul>"
140
  else:
141
  out += "<i>No academic references found.</i><br>"
142
 
143
  if links:
144
- out += "<b>Top Web Resources:</b><ul>"
145
  for link in links:
146
  out += f"<li><b>{link['title']}</b><br>{link['snippet']}<br><a href='{link['url']}' target='_blank'>{link['url']}</a></li>"
147
  out += "</ul>"
@@ -154,8 +134,8 @@ iface = gr.Interface(
154
  fn=classify_math_question,
155
  inputs=gr.Textbox(lines=5, label="Enter Math Question (LaTeX supported)"),
156
  outputs=gr.HTML(label="Predicted Domains + References"),
157
- title="📚 Math Domain Classifier with arXiv + Semantic Scholar + DuckDuckGo",
158
- description="Paste any math problem or LaTeX expression and get its major/minor domains + academic references + web links."
159
  )
160
 
161
  iface.launch()
 
65
  domain_texts = list(DOMAINS.values())
66
  domain_embeddings = model.encode(domain_texts)
67
 
68
+ def fetch_arxiv_refs(query, max_results=3):
69
+ refs = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  try:
71
+ search = arxiv.Search(query=query, max_results=max_results)
72
  for r in search.results():
73
+ refs.append({
74
  "title": r.title,
75
  "authors": ", ".join(a.name for a in r.authors[:3]),
76
  "year": r.published.year,
 
79
  })
80
  except:
81
  pass
82
+ return refs
83
 
84
+ def fetch_duckduckgo_links(query, max_results=3):
 
 
85
  links = []
86
  try:
87
  with DDGS() as ddgs:
 
109
  out = f"<b>Major Domain:</b> {major}<br><i>Reason:</i> {major_reason}<br><br>"
110
  out += f"<b>Minor Domain:</b> {minor}<br><i>Reason:</i> {minor_reason}<br><br>"
111
 
112
+ refs = fetch_arxiv_refs(question, max_results=3)
113
+ links = fetch_duckduckgo_links(question, max_results=3)
114
 
115
  if refs:
116
+ out += "<b>Top Academic References (arXiv):</b><ul>"
117
  for p in refs:
118
+ out += f"<li><b>{p['title']}</b> ({p['year']}) - <i>{p['authors']}</i><br><a href='{p['url']}' target='_blank'>{p['url']}</a></li>"
119
  out += "</ul>"
120
  else:
121
  out += "<i>No academic references found.</i><br>"
122
 
123
  if links:
124
+ out += "<b>Top Web Resources (DuckDuckGo):</b><ul>"
125
  for link in links:
126
  out += f"<li><b>{link['title']}</b><br>{link['snippet']}<br><a href='{link['url']}' target='_blank'>{link['url']}</a></li>"
127
  out += "</ul>"
 
134
  fn=classify_math_question,
135
  inputs=gr.Textbox(lines=5, label="Enter Math Question (LaTeX supported)"),
136
  outputs=gr.HTML(label="Predicted Domains + References"),
137
+ title=" Fast Math Domain Classifier with arXiv + DuckDuckGo",
138
+ description="Classifies math problems into major/minor domains and fetches fast references from arXiv + DuckDuckGo."
139
  )
140
 
141
  iface.launch()