Nymbo commited on
Commit
2ab842f
Β·
verified Β·
1 Parent(s): 21f0d84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -4,24 +4,19 @@
4
  # 2) Websearch β€” structured DuckDuckGo search via LangChain tool (JSON)
5
  # 3) Unstructured DDG β€” raw DuckDuckGo list[dict] rendered into a Textbox
6
  # 4) DDG (Concise) β€” ultra-succinct DuckDuckGo search that emits JSONL with short keys to minimize tokens
7
- #
8
- # Launched with mcp_server=True so all functions are available as MCP tools.
9
 
10
  from __future__ import annotations
11
 
12
- import re # (layman) whitespace cleanup and trimming
13
- import json # (layman) to produce compact JSON lines
14
  from typing import List, Dict, Literal, Tuple
15
 
16
- import gradio as gr # (layman) UI framework
17
- import requests # (layman) to download web pages
18
- from bs4 import BeautifulSoup # (layman) HTML parsing
19
- from readability import Document # (layman) isolate main article content
20
- from urllib.parse import urljoin, urldefrag, urlparse # (layman) URL helpers
21
-
22
- # Structured search via LangChain community tool
23
  from langchain_community.tools import DuckDuckGoSearchResults
24
- # Native DDG client (used by Unstructured + Concise tabs)
25
  from duckduckgo_search import DDGS
26
 
27
 
@@ -246,7 +241,7 @@ def _format_markdown(
246
  return "\n\n".join(lines).strip()
247
 
248
 
249
- def extract_relevant( # <-- MCP tool #1 (Fetch)
250
  url: str,
251
  verbosity: str = "Standard",
252
  include_metadata: bool = True,
@@ -256,7 +251,7 @@ def extract_relevant( # <-- MCP tool #1 (Fetch)
256
  max_links: int = 20,
257
  ) -> str:
258
  """
259
- (layman) Given a URL, return a tight Markdown summary: title, key metadata, readable text, and links.
260
  """
261
  if not url or not url.strip():
262
  return "Please enter a valid URL."
@@ -314,7 +309,7 @@ def extract_relevant( # <-- MCP tool #1 (Fetch)
314
  # Websearch: DuckDuckGo tool
315
  # ==========================
316
 
317
- def web_search( # <-- MCP tool #2 (Structured DDG)
318
  input_query: str,
319
  max_results: int = 5,
320
  ) -> List[Dict[Literal["snippet", "title", "link"], str]]:
@@ -336,7 +331,7 @@ def web_search( # <-- MCP tool #2 (Structured DDG)
336
  # Unstructured DDG: raw list into Textbox
337
  # ========================================
338
 
339
- def ddg_unstructured( # <-- MCP tool #3 (Unstructured DDG)
340
  query: str,
341
  ) -> list[dict]:
342
  """
@@ -353,7 +348,7 @@ def ddg_unstructured( # <-- MCP tool #3 (Unstructured DDG)
353
  # Concise DDG: ultra-succinct JSONL for tokens
354
  # ============================================
355
 
356
- def ddg_concise( # <-- MCP tool #4 (Concise DDG)
357
  query: str,
358
  max_results: int = 5,
359
  include_snippets: bool = False,
 
4
  # 2) Websearch β€” structured DuckDuckGo search via LangChain tool (JSON)
5
  # 3) Unstructured DDG β€” raw DuckDuckGo list[dict] rendered into a Textbox
6
  # 4) DDG (Concise) β€” ultra-succinct DuckDuckGo search that emits JSONL with short keys to minimize tokens
 
 
7
 
8
  from __future__ import annotations
9
 
10
+ import re
11
+ import json
12
  from typing import List, Dict, Literal, Tuple
13
 
14
+ import gradio as gr
15
+ import requests
16
+ from bs4 import BeautifulSoup
17
+ from readability import Document
18
+ from urllib.parse import urljoin, urldefrag, urlparse
 
 
19
  from langchain_community.tools import DuckDuckGoSearchResults
 
20
  from duckduckgo_search import DDGS
21
 
22
 
 
241
  return "\n\n".join(lines).strip()
242
 
243
 
244
+ def Fetch_Webpage( # <-- MCP tool #1 (Fetch)
245
  url: str,
246
  verbosity: str = "Standard",
247
  include_metadata: bool = True,
 
251
  max_links: int = 20,
252
  ) -> str:
253
  """
254
+ Given a URL, return a tight Markdown summary: title, key metadata, readable text, and links.
255
  """
256
  if not url or not url.strip():
257
  return "Please enter a valid URL."
 
309
  # Websearch: DuckDuckGo tool
310
  # ==========================
311
 
312
+ def Search_Structured( # <-- MCP tool #2 (Structured DDG)
313
  input_query: str,
314
  max_results: int = 5,
315
  ) -> List[Dict[Literal["snippet", "title", "link"], str]]:
 
331
  # Unstructured DDG: raw list into Textbox
332
  # ========================================
333
 
334
+ def Search_Raw( # <-- MCP tool #3 (Unstructured DDG)
335
  query: str,
336
  ) -> list[dict]:
337
  """
 
348
  # Concise DDG: ultra-succinct JSONL for tokens
349
  # ============================================
350
 
351
+ def Search_Concise( # <-- MCP tool #4 (Concise DDG)
352
  query: str,
353
  max_results: int = 5,
354
  include_snippets: bool = False,