Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ HEADERS = {"X-API-KEY": SERPER_API_KEY, "Content-Type": "application/json"}
|
|
| 21 |
|
| 22 |
|
| 23 |
### 1 ─ Serper call -------------------------------------------------------------
|
| 24 |
-
async def get_serper_news(query: str, num: int =
|
| 25 |
payload = {"q": query, "type": "news", "num": num, "page": 1}
|
| 26 |
async with httpx.AsyncClient(timeout=15) as client:
|
| 27 |
resp = await client.post(SERPER_ENDPOINT, headers=HEADERS, json=payload)
|
|
@@ -55,7 +55,7 @@ def extract_main_text(html: str) -> str:
|
|
| 55 |
|
| 56 |
|
| 57 |
### 4 ─ Orchestration -----------------------------------------------------------
|
| 58 |
-
async def build_context(query: str, k: int =
|
| 59 |
news_items = await get_serper_news(query, num=k)
|
| 60 |
urls = [n["link"] for n in news_items]
|
| 61 |
raw_pages = await fetch_html_many(urls)
|
|
@@ -94,7 +94,7 @@ async def handler(user_query: str, k: int) -> str:
|
|
| 94 |
with gr.Blocks(title="WebSearch") as demo:
|
| 95 |
gr.Markdown("# 🔍 Web Search\n" "Feed LLMs with fresh sources.")
|
| 96 |
query = gr.Textbox(label="Query", placeholder='e.g. "apple inc"')
|
| 97 |
-
top_k = gr.Slider(1, 20, value=
|
| 98 |
out = gr.Textbox(label="Extracted Context", lines=25)
|
| 99 |
run = gr.Button("Fetch")
|
| 100 |
run.click(handler, inputs=[query, top_k], outputs=out)
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
### 1 ─ Serper call -------------------------------------------------------------
|
| 24 |
+
async def get_serper_news(query: str, num: int = 4) -> list[dict]:
|
| 25 |
payload = {"q": query, "type": "news", "num": num, "page": 1}
|
| 26 |
async with httpx.AsyncClient(timeout=15) as client:
|
| 27 |
resp = await client.post(SERPER_ENDPOINT, headers=HEADERS, json=payload)
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
### 4 ─ Orchestration -----------------------------------------------------------
|
| 58 |
+
async def build_context(query: str, k: int = 4) -> str:
|
| 59 |
news_items = await get_serper_news(query, num=k)
|
| 60 |
urls = [n["link"] for n in news_items]
|
| 61 |
raw_pages = await fetch_html_many(urls)
|
|
|
|
| 94 |
with gr.Blocks(title="WebSearch") as demo:
|
| 95 |
gr.Markdown("# 🔍 Web Search\n" "Feed LLMs with fresh sources.")
|
| 96 |
query = gr.Textbox(label="Query", placeholder='e.g. "apple inc"')
|
| 97 |
+
top_k = gr.Slider(1, 20, value=4, label="How many results?")
|
| 98 |
out = gr.Textbox(label="Extracted Context", lines=25)
|
| 99 |
run = gr.Button("Fetch")
|
| 100 |
run.click(handler, inputs=[query, top_k], outputs=out)
|