kfahn commited on
Commit
5422b86
·
verified ·
1 Parent(s): 369a3f5

Update app.py

Browse files

Try adding random cat image tool

Files changed (1) hide show
  1. app.py +72 -0
app.py CHANGED
@@ -18,6 +18,78 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_joke() -> str:
23
  """
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ #https://huggingface.co/black-forest-labs/FLUX.1-dev
22
+ #@tool
23
+ # def image_generation_tool = Tool.from_space(
24
+ # "black-forest-labs/FLUX.1-schnell",
25
+ # name="image_generator",
26
+ # description="Generate an image from a prompt"
27
+ # )
28
+
29
+ #https://zenquotes.io/api/quotes/[YOUR_API_KEY]&keyword=${category}
30
+
31
+ # @tool
32
+ # def zenquotes(category: str) -> str:
33
+ # """
34
+ # Get a quote using the Zenquotes API.
35
+
36
+ # Args:
37
+ # category: The category for the quote.
38
+
39
+
40
+ # Returns:
41
+ # A string with the quote.
42
+ # """
43
+ # api_key = "your_api_key" # Replace with your API key from https://weatherstack.com/
44
+
45
+
46
+ # //url = f"http://api.weatherstack.com/current?access_key={api_key}&query={location}&units={units}"
47
+ # url = f"https://zenquotes.io/api/quotes/[YOUR_API_KEY]&keyword=${category}"
48
+
49
+ # try:
50
+ # response = requests.get(url)
51
+ # response.raise_for_status() # Raise an exception for HTTP errors
52
+
53
+ # data = response.json()
54
+
55
+ # if data.get("error"): # Check if there's an error in the response
56
+ # return f"Error: {data['error'].get('info', 'Unable to fetch a quote.')}"
57
+
58
+ # quote = data["category"][0]
59
+
60
+ # return f"Here is your quote about {category}: ."
61
+
62
+ # except requests.exceptions.RequestException as e:
63
+ # return f"Error fetching quote: {str(e)}"
64
+
65
+
66
+ @tool
67
+ def random_cat_image() -> image:
68
+ """
69
+ Fetches a random cat image from aws.random.cat.
70
+ This function sends a GET request to the api to retrieve a random cat image.
71
+ If the request fails or the response does not contain a cat image, an error message is returned.
72
+ Returns:
73
+ image: The cat image, or an error message if the image could not be fetched.
74
+ """
75
+ url = "https://aws.random.cat/meow"
76
+
77
+ try:
78
+ response = requests.get(url)
79
+ response.raise_for_status()
80
+
81
+ data = response.json()
82
+
83
+ if "image" in data:
84
+ return data["image"]
85
+ elif "setup" in data and "delivery" in data:
86
+ return f"{data['setup']} - {data['delivery']}"
87
+ else:
88
+ return "Error: Unable to fetch cat image."
89
+
90
+ except requests.exceptions.RequestException as e:
91
+ return f"Error fetching cat image: {str(e)}"
92
+
93
  @tool
94
  def get_joke() -> str:
95
  """