Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from bs4 import BeautifulSoup
|
| 8 |
-
from
|
| 9 |
import requests
|
| 10 |
from io import BytesIO
|
| 11 |
from PIL import Image
|
|
@@ -86,9 +86,24 @@ def get_all_matches_for_a_date(date: str) -> str:
|
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error fetching matches for {date}: {str(e)}"
|
| 88 |
|
| 89 |
-
|
| 90 |
web_serach_tool = DuckDuckGoSearchTool()
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
@tool
|
| 94 |
def get_news(topic: str) -> str:
|
|
@@ -118,12 +133,16 @@ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',#
|
|
| 118 |
custom_role_conversions=None,
|
| 119 |
)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
with open("prompts.yaml", 'r') as stream:
|
| 122 |
prompt_templates = yaml.safe_load(stream)
|
| 123 |
|
| 124 |
agent = CodeAgent(
|
| 125 |
model=model,
|
| 126 |
-
tools=[get_all_matches_for_a_date,
|
| 127 |
max_steps=6,
|
| 128 |
verbosity_level=1,
|
| 129 |
grammar=None,
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from bs4 import BeautifulSoup
|
| 8 |
+
from Gradio_UI import GradioUI
|
| 9 |
import requests
|
| 10 |
from io import BytesIO
|
| 11 |
from PIL import Image
|
|
|
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error fetching matches for {date}: {str(e)}"
|
| 88 |
|
|
|
|
| 89 |
web_serach_tool = DuckDuckGoSearchTool()
|
| 90 |
|
| 91 |
+
@tool
|
| 92 |
+
def generate_image(imageprompt: str) -> Image.Image:
|
| 93 |
+
"""A tool that generates an image based on a given prompt.
|
| 94 |
+
Args:
|
| 95 |
+
imageprompt: The description of the image to generate.
|
| 96 |
+
Returns:
|
| 97 |
+
The generated image as a PIL Image object.
|
| 98 |
+
"""
|
| 99 |
+
url = f"https://image.pollinations.ai/prompt/{imageprompt}"
|
| 100 |
+
response = requests.get(url)
|
| 101 |
+
|
| 102 |
+
if response.status_code == 200:
|
| 103 |
+
return Image.open(BytesIO(response.content))
|
| 104 |
+
else:
|
| 105 |
+
raise Exception("Failed to generate image.")
|
| 106 |
+
|
| 107 |
|
| 108 |
@tool
|
| 109 |
def get_news(topic: str) -> str:
|
|
|
|
| 133 |
custom_role_conversions=None,
|
| 134 |
)
|
| 135 |
|
| 136 |
+
|
| 137 |
+
# Import tool from Hub
|
| 138 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 139 |
+
|
| 140 |
with open("prompts.yaml", 'r') as stream:
|
| 141 |
prompt_templates = yaml.safe_load(stream)
|
| 142 |
|
| 143 |
agent = CodeAgent(
|
| 144 |
model=model,
|
| 145 |
+
tools=[get_all_matches_for_a_date,get_news, generate_image, get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)
|
| 146 |
max_steps=6,
|
| 147 |
verbosity_level=1,
|
| 148 |
grammar=None,
|