Spaces:
Sleeping
Sleeping
Add tools
Browse files
app.py
CHANGED
|
@@ -13,7 +13,8 @@ async def make_request(url: str, data: Dict[str, Any]):
|
|
| 13 |
return response.json()
|
| 14 |
except:
|
| 15 |
return None
|
| 16 |
-
|
|
|
|
| 17 |
@server.tool()
|
| 18 |
async def search_academic_papers_arxiv(keyword: str, limit: int = 5) -> str:
|
| 19 |
"""
|
|
@@ -37,6 +38,7 @@ async def get_arxiv_pub_text(arxiv_id: str) -> str:
|
|
| 37 |
return "Unable to extract PDF | arXiv PDF not found"
|
| 38 |
return response["message"]["text"]
|
| 39 |
|
|
|
|
| 40 |
@server.tool()
|
| 41 |
async def get_document_url(doc_id: str) -> str:
|
| 42 |
"""
|
|
@@ -68,8 +70,9 @@ async def search_specifications_with_keywords(keywords: str, threshold: int = 60
|
|
| 68 |
results = response["results"]
|
| 69 |
return "\n---\n".join([f"Specification ID: {spec['id']}\nTitle: {spec['title']}\nType: {'Technical Specification' if spec['spec_type'] == 'TS' else 'Technical Report'}\nVersion: {spec.get('version', 'unavailable')}\nScope: {spec.get('scope', 'unavailable')}\nWorking Group: {spec.get('working_group', 'not defined')}\nURL: {spec.get('url', 'unavailable')}" for spec in results])
|
| 70 |
|
|
|
|
| 71 |
@server.tool()
|
| 72 |
-
async def get_spec_text(spec_id: str) ->
|
| 73 |
"""
|
| 74 |
Extract specification from 3GPP or ETSI
|
| 75 |
Returns a dictionary k:v where k is the section (1., 2.2.1, ...) and v, the content of k, or a string if failed
|
|
@@ -78,6 +81,20 @@ async def get_spec_text(spec_id: str) -> Union[Dict[str, str], str]:
|
|
| 78 |
response = await make_request('https://organizedprogrammers-specsplitter.hf.space/extract_text/structured', {"spec_id": spec_id})
|
| 79 |
if not response:
|
| 80 |
return "Unable to extract specification text"
|
| 81 |
-
return response
|
|
|
|
|
|
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
app = server.streamable_http_app
|
|
|
|
| 13 |
return response.json()
|
| 14 |
except:
|
| 15 |
return None
|
| 16 |
+
|
| 17 |
+
# arXiv
|
| 18 |
@server.tool()
|
| 19 |
async def search_academic_papers_arxiv(keyword: str, limit: int = 5) -> str:
|
| 20 |
"""
|
|
|
|
| 38 |
return "Unable to extract PDF | arXiv PDF not found"
|
| 39 |
return response["message"]["text"]
|
| 40 |
|
| 41 |
+
# DocFinder
|
| 42 |
@server.tool()
|
| 43 |
async def get_document_url(doc_id: str) -> str:
|
| 44 |
"""
|
|
|
|
| 70 |
results = response["results"]
|
| 71 |
return "\n---\n".join([f"Specification ID: {spec['id']}\nTitle: {spec['title']}\nType: {'Technical Specification' if spec['spec_type'] == 'TS' else 'Technical Report'}\nVersion: {spec.get('version', 'unavailable')}\nScope: {spec.get('scope', 'unavailable')}\nWorking Group: {spec.get('working_group', 'not defined')}\nURL: {spec.get('url', 'unavailable')}" for spec in results])
|
| 72 |
|
| 73 |
+
# SpecSplitter
|
| 74 |
@server.tool()
|
| 75 |
+
async def get_spec_text(spec_id: str) -> str:
|
| 76 |
"""
|
| 77 |
Extract specification from 3GPP or ETSI
|
| 78 |
Returns a dictionary k:v where k is the section (1., 2.2.1, ...) and v, the content of k, or a string if failed
|
|
|
|
| 81 |
response = await make_request('https://organizedprogrammers-specsplitter.hf.space/extract_text/structured', {"spec_id": spec_id})
|
| 82 |
if not response:
|
| 83 |
return "Unable to extract specification text"
|
| 84 |
+
return "\n".join([f"{k}: {v}" for k, v in response.keys()])
|
| 85 |
+
|
| 86 |
+
# SERPent
|
| 87 |
|
| 88 |
+
@server.tool()
|
| 89 |
+
async def search_google_patents(queries: List[str], n_results: int) -> str:
|
| 90 |
+
"""
|
| 91 |
+
Search patents from Google Patents
|
| 92 |
+
You can generate multiple queries (at least 1)
|
| 93 |
+
Returns a list of patents from queries, for each query, {n_results} patents will be retrieved
|
| 94 |
+
Args: queries -> list of string, n_results -> integer [by default: 10]
|
| 95 |
+
"""
|
| 96 |
+
response = await make_request("https://organizedprogrammers-serpent.hf.space/serp/search_patents", {"queries": queries, "n_results": n_results})
|
| 97 |
+
if not response:
|
| 98 |
+
return "Unable to fetch patents"
|
| 99 |
+
return "\n".join(f"[Patent ID: {patent['id']} | Title: {patent['title']} | Body: {patent['body']}]" for patent in response.results)
|
| 100 |
app = server.streamable_http_app
|