Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,22 @@
|
|
| 1 |
-
from smolagents import CodeAgent,
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
|
|
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 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
|
|
@@ -53,9 +64,12 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 53 |
with open("prompts.yaml", 'r') as stream:
|
| 54 |
prompt_templates = yaml.safe_load(stream)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
@@ -65,5 +79,16 @@ agent = CodeAgent(
|
|
| 65 |
prompt_templates=prompt_templates
|
| 66 |
)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
|
|
|
|
|
|
| 69 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
+
import threading
|
| 7 |
+
import logging
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
+
from tools.web_search import DuckDuckGoSearchTool
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
+
from telegram_bot import start_telegram_bot
|
| 13 |
+
|
| 14 |
+
# Setup logging
|
| 15 |
+
logging.basicConfig(
|
| 16 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 17 |
+
level=logging.INFO
|
| 18 |
+
)
|
| 19 |
+
logger = logging.getLogger(__name__)
|
| 20 |
|
| 21 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 22 |
@tool
|
|
|
|
| 64 |
with open("prompts.yaml", 'r') as stream:
|
| 65 |
prompt_templates = yaml.safe_load(stream)
|
| 66 |
|
| 67 |
+
# Initialize the web search tool
|
| 68 |
+
web_search = DuckDuckGoSearchTool()
|
| 69 |
+
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[web_search, final_answer], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|
|
|
|
| 79 |
prompt_templates=prompt_templates
|
| 80 |
)
|
| 81 |
|
| 82 |
+
# Start Telegram bot in a separate daemon thread
|
| 83 |
+
logger.info("Starting Telegram bot in background thread...")
|
| 84 |
+
telegram_thread = threading.Thread(
|
| 85 |
+
target=start_telegram_bot,
|
| 86 |
+
args=(agent,),
|
| 87 |
+
daemon=True # Daemon thread will exit when main program exits
|
| 88 |
+
)
|
| 89 |
+
telegram_thread.start()
|
| 90 |
+
logger.info("Telegram bot thread started!")
|
| 91 |
|
| 92 |
+
# Launch Gradio UI in main thread (this blocks)
|
| 93 |
+
logger.info("Starting Gradio UI...")
|
| 94 |
GradioUI(agent).launch()
|