Update app.py
#2
by
CindyDelage
- opened
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from tools import Web_research,
|
| 7 |
from smolagents import GradioUI, CodeAgent, HfApiModel, PythonInterpreterTool
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
|
@@ -19,24 +19,25 @@ class BasicAgent:
|
|
| 19 |
print("BasicAgent initialized.")
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
web_search = Web_research()
|
| 22 |
-
|
| 23 |
python_code_tool = PythonInterpreterTool()
|
| 24 |
wiki_tool = Wikipedia_reader()
|
| 25 |
translator=translate_everything()
|
| 26 |
wiki_url_tool=Find_wikipedia_URL()
|
|
|
|
| 27 |
alfred=CodeAgent(
|
| 28 |
-
tools=[translator,wiki_tool,wiki_url_tool,web_search,
|
| 29 |
model=HfApiModel(token=os.environ.get("HF_TOKEN")),
|
| 30 |
add_base_tools=True,
|
| 31 |
additional_authorized_imports=['urllib','chess','requests', 'bs4'],
|
| 32 |
-
max_print_outputs_length =
|
| 33 |
)
|
| 34 |
HF_TOKEN=os.environ.get("HF_TOKEN")
|
| 35 |
headers = {
|
| 36 |
"Authorization": f"Bearer {HF_TOKEN}"
|
| 37 |
}
|
| 38 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 39 |
-
fixed_answer = alfred.run(f"You are a general AI assistant. I will ask you a question. You have custom tools in the file tools.py and you must use them whenever you can to answer the questions. Mainly, you
|
| 40 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 41 |
return fixed_answer
|
| 42 |
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from tools import Web_research, multimodal_interpreter, Wikipedia_reader, translate_everything, Find_wikipedia_URL, audio_or_mp3__interpreter
|
| 7 |
from smolagents import GradioUI, CodeAgent, HfApiModel, PythonInterpreterTool
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
|
|
|
| 19 |
print("BasicAgent initialized.")
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
web_search = Web_research()
|
| 22 |
+
multimodal_tool = multimodal_interpreter()
|
| 23 |
python_code_tool = PythonInterpreterTool()
|
| 24 |
wiki_tool = Wikipedia_reader()
|
| 25 |
translator=translate_everything()
|
| 26 |
wiki_url_tool=Find_wikipedia_URL()
|
| 27 |
+
audio_tool=audio_or_mp3__interpreter()
|
| 28 |
alfred=CodeAgent(
|
| 29 |
+
tools=[translator,wiki_tool,wiki_url_tool,web_search, multimodal_tool,python_code_tool, audio_tool],
|
| 30 |
model=HfApiModel(token=os.environ.get("HF_TOKEN")),
|
| 31 |
add_base_tools=True,
|
| 32 |
additional_authorized_imports=['urllib','chess','requests', 'bs4'],
|
| 33 |
+
max_print_outputs_length = 100
|
| 34 |
)
|
| 35 |
HF_TOKEN=os.environ.get("HF_TOKEN")
|
| 36 |
headers = {
|
| 37 |
"Authorization": f"Bearer {HF_TOKEN}"
|
| 38 |
}
|
| 39 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 40 |
+
fixed_answer = alfred.run(f"You are a general AI assistant. I will ask you a question. You have custom tools in the file tools.py and you must use them whenever you can to answer the questions. Mainly, use wiki_url_tool to know a wikipedia url on a specific subject. When you need informations, always start with wikipedia and always use wiki_tool to extract the full content of wikipedia pages. You also have a tool for multimodal inputs and one for audio inputs. You must use them in priority if needed, before thinking of anything else. Report your thoughts and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. Here are the questions : {question}")
|
| 41 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 42 |
return fixed_answer
|
| 43 |
|