Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,47 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def count_letter(word:str, letter:str) -> int:
|
4 |
-
"""
|
5 |
-
Count the occurrences of a letter in a word/text.
|
6 |
Args:
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
Returns:
|
10 |
-
|
11 |
"""
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
return
|
|
|
16 |
|
17 |
-
#
|
18 |
demo = gr.Interface(
|
19 |
-
fn=
|
20 |
-
inputs=[
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
-
|
26 |
-
|
27 |
-
demo.launch(mcp_server=True,
|
28 |
-
share=True) #to create a public link
|
|
|
1 |
import gradio as gr
|
2 |
+
from duckduckgo_search import DDGS
|
3 |
+
|
4 |
+
|
5 |
+
def news(
|
6 |
+
keywords: str,
|
7 |
+
region: str = "wt-wt",
|
8 |
+
safesearch: str = "moderate",
|
9 |
+
timelimit: str | None = None,
|
10 |
+
max_results: int | None = None,
|
11 |
+
) -> list[dict[str, str]]:
|
12 |
+
"""DuckDuckGo news search. Query params: https://duckduckgo.com/params.
|
13 |
|
|
|
|
|
|
|
14 |
Args:
|
15 |
+
keywords: keywords for query.
|
16 |
+
region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
|
17 |
+
safesearch: on, moderate, off. Defaults to "moderate".
|
18 |
+
timelimit: d, w, m. Defaults to None.
|
19 |
+
max_results: max number of results. If None, returns results only from the first response. Defaults to None.
|
20 |
+
|
21 |
Returns:
|
22 |
+
List of dictionaries with news search results.
|
23 |
"""
|
24 |
+
# Fix: Use the keywords parameter instead of hardcoded "sun"
|
25 |
+
results = DDGS().news(keywords=keywords, region=region,
|
26 |
+
safesearch=safesearch, timelimit=timelimit, max_results=max_results)
|
27 |
+
return list(results) # Convert generator to list and return it
|
28 |
+
|
29 |
|
30 |
+
# Create a Gradio interface for the news function
|
31 |
demo = gr.Interface(
|
32 |
+
fn=news,
|
33 |
+
inputs=[
|
34 |
+
gr.Textbox(label="Keywords"),
|
35 |
+
gr.Dropdown(["wt-wt", "us-en", "uk-en"],
|
36 |
+
label="Region", value="wt-wt"),
|
37 |
+
gr.Dropdown(["on", "moderate", "off"],
|
38 |
+
label="Safe Search", value="moderate"),
|
39 |
+
gr.Dropdown([None, "d", "w", "m"], label="Time Limit", value=None),
|
40 |
+
gr.Number(label="Max Results", value=10)
|
41 |
+
],
|
42 |
+
outputs=gr.JSON(),
|
43 |
+
title="News Search",
|
44 |
+
description="Search for news using DuckDuckGo"
|
45 |
)
|
46 |
+
|
47 |
+
demo.launch(mcp_server=True)
|
|
|
|