Update app.py
#396
by
ghada2
- opened
app.py
CHANGED
@@ -8,16 +8,46 @@ from tools.final_answer import FinalAnswerTool
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
@tool
|
12 |
-
def my_custom_tool(
|
13 |
-
|
14 |
-
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
+
# @tool
|
12 |
+
# def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
13 |
+
# #Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
+
# """A tool that does nothing yet
|
15 |
+
# Args:
|
16 |
+
# arg1: the first argument
|
17 |
+
# arg2: the second argument
|
18 |
+
# """
|
19 |
+
# return "What magic will you build ?"
|
20 |
+
# Exemple d'utilisation de DuckDuckGoSearchTool
|
21 |
+
duckduckgo = DuckDuckGoSearchTool()
|
22 |
+
|
23 |
+
# Chargement d’un outil d’image depuis le Hub (à adapter selon ton environnement)
|
24 |
+
image_generation_tool = load_tool("image-generator")
|
25 |
+
|
26 |
+
# Un outil personnalisé qui combine recherche et génération d’image
|
27 |
@tool
|
28 |
+
def my_custom_tool(topic: str, n_results: int) -> str:
|
29 |
+
"""
|
30 |
+
Recherche des infos avec DuckDuckGo, puis génère une image à partir du thème.
|
31 |
+
|
32 |
Args:
|
33 |
+
topic: Le sujet de la recherche
|
34 |
+
n_results: Le nombre de résultats à afficher
|
35 |
+
|
36 |
+
Returns:
|
37 |
+
Une phrase résumant la recherche et l’URL de l’image générée
|
38 |
"""
|
39 |
+
search_results = duckduckgo(topic, n_results=n_results)
|
40 |
+
if not search_results:
|
41 |
+
return "Aucun résultat trouvé pour ce sujet."
|
42 |
+
|
43 |
+
summary = "\n".join([f"{i+1}. {res['body']}" for i, res in enumerate(search_results)])
|
44 |
+
|
45 |
+
# Génère une image liée au sujet
|
46 |
+
image = image_generation_tool(prompt=topic)
|
47 |
+
|
48 |
+
return f"Résultats de recherche pour '{topic}':\n{summary}\n\nImage générée pour ce sujet : {image}"
|
49 |
|
50 |
+
|
51 |
@tool
|
52 |
def get_current_time_in_timezone(timezone: str) -> str:
|
53 |
"""A tool that fetches the current local time in a specified timezone.
|