Juank0621 commited on
Commit
eb0be82
·
verified ·
1 Parent(s): 0ad29e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -7,30 +7,30 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- from diffusers import StableDiffusionPipeline
11
- import torch
12
- from io import BytesIO
13
-
14
- # Load Stable Diffusion Model
15
- pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
16
- pipeline.to("cuda") # Use GPU if available
17
-
18
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
19
  @tool
20
- def my_custom_tool(prompt: str, steps: int = 50, guidance_scale: float = 7.5) -> bytes:
21
- """Generates an image based on a text prompt using Stable Diffusion.
22
  Args:
23
- prompt: The description of the image.
24
- steps: Number of inference steps (default is 50 for quality balance).
25
- guidance_scale: How much the model follows the text (default is 7.5).
26
  Returns:
27
- The generated image in bytes (PNG format).
28
  """
29
- image = pipeline(prompt, num_inference_steps=steps, guidance_scale=guidance_scale).images[0]
30
- img_byte_arr = BytesIO()
31
- image.save(img_byte_arr, format='PNG')
32
- return img_byte_arr.getvalue()
33
-
 
 
 
 
 
 
 
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str:
36
  """A tool that fetches the current local time in a specified timezone.
 
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 currency_converter(amount: float, from_currency: str, to_currency: str) -> str:
13
+ """Converts an amount from one currency to another using real-time exchange rates.
14
  Args:
15
+ amount: The amount of money to convert.
16
+ from_currency: The currency code to convert from (e.g., 'USD').
17
+ to_currency: The currency code to convert to (e.g., 'EUR').
18
  Returns:
19
+ A string with the converted amount and exchange rate.
20
  """
21
+ api_url = f"https://api.frankfurter.app/latest?from={from_currency.upper()}&to={to_currency.upper()}"
22
+ try:
23
+ response = requests.get(api_url)
24
+ data = response.json()
25
+ if 'rates' in data and to_currency.upper() in data['rates']:
26
+ rate = data['rates'][to_currency.upper()]
27
+ converted_amount = amount * rate
28
+ return f"{amount} {from_currency.upper()} = {converted_amount:.2f} {to_currency.upper()} (Rate: {rate})"
29
+ else:
30
+ return "Invalid currency code."
31
+ except Exception as e:
32
+ return f"Error fetching exchange rate: {str(e)}"
33
+
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str:
36
  """A tool that fetches the current local time in a specified timezone.