baxin commited on
Commit
d09190e
·
verified ·
1 Parent(s): ebcfb0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
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
- word (str): the input text to search through
8
- letter(str): the letter to search for
 
 
 
 
9
  Returns:
10
- int: the number of times the letter appears in the word/text.
11
  """
12
- word = word.lower()
13
- letter = letter.lower()
14
- count = word.count(letter)
15
- return count
 
16
 
17
- # create a standard gradio ui
18
  demo = gr.Interface(
19
- fn=count_letter,
20
- inputs=['textbox', 'textbox'],
21
- outputs='number',
22
- title='Letter Counter',
23
- description="Enter text and a letter to count how many times the letter appears in the text."
 
 
 
 
 
 
 
 
24
  )
25
- # launch both the Gradio web interface and the MCP server
26
- if __name__=='__main__':
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)