Spaces:
Sleeping
Sleeping
add get_gif tool
Browse files
app.py
CHANGED
|
@@ -4,9 +4,42 @@ 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
|
| 12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
@@ -55,7 +88,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer, image_generation_tool,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import giphy_client
|
| 8 |
+
from giphy_client.rest import ApiException
|
| 9 |
+
import random
|
| 10 |
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
API_KEY = "TUIRcl9MzEBwR4p3eoF8LmMmwQQXXtPq" # ← replace with your actual key
|
| 16 |
+
|
| 17 |
+
api = giphy_client.DefaultApi()
|
| 18 |
+
|
| 19 |
+
@tool
|
| 20 |
+
def get_gif(query: str) -> str:
|
| 21 |
+
"""Fetch a single GIF URL from GIPHY based on a search query.
|
| 22 |
+
Args:
|
| 23 |
+
query (str): The search term (e.g. "funny cat", "excited", "monday mood").
|
| 24 |
+
Returns:
|
| 25 |
+
str: The URL of a randomly selected GIF that matches the query,
|
| 26 |
+
or None if no results are found or an API error occurs.
|
| 27 |
+
Example:
|
| 28 |
+
>>> get_gif("funny dog")
|
| 29 |
+
'https://media2.giphy.com/media/l0MYt5jPR6QX5pnqM/giphy.gif'
|
| 30 |
+
"""
|
| 31 |
+
try:
|
| 32 |
+
res = api.gifs_search_get(API_KEY, q=query, limit=10, rating="pg")
|
| 33 |
+
if not res.data:
|
| 34 |
+
return None
|
| 35 |
+
gif = random.choice(res.data)
|
| 36 |
+
return gif.images.original.url
|
| 37 |
+
except ApiException as e:
|
| 38 |
+
print("Giphy API error:", e)
|
| 39 |
+
return None
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 44 |
@tool
|
| 45 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 88 |
|
| 89 |
agent = CodeAgent(
|
| 90 |
model=model,
|
| 91 |
+
tools=[final_answer, image_generation_tool,get_current_time_in_timezone, get_gif], ## add your tools here (don't remove final answer)
|
| 92 |
max_steps=6,
|
| 93 |
verbosity_level=1,
|
| 94 |
grammar=None,
|