umarigan commited on
Commit
c79af1e
·
verified ·
1 Parent(s): 45af8bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -1,15 +1,12 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool,OpenAIServerModel
2
  import datetime
3
- import requests
4
  import pytz
5
- import yaml
6
- from tools.final_answer import FinalAnswerTool
7
  import os
8
  from Gradio_UI import GradioUI
9
  import gradio as gr
10
- import requests
11
- import yfinance as yf
12
 
 
13
  API_KEY = os.getenv("KEY")
14
 
15
  @tool
@@ -27,6 +24,7 @@ def get_currency_rate(currency_pair: str) -> str:
27
  return f"Current {currency_pair} rate: {rate}"
28
  except Exception as e:
29
  return f"Error fetching rate: {str(e)}"
 
30
  @tool
31
  def get_current_time_in_timezone(timezone: str) -> str:
32
  """A tool that fetches the current local time in a specified timezone.
@@ -42,25 +40,27 @@ def get_current_time_in_timezone(timezone: str) -> str:
42
  except Exception as e:
43
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
44
 
 
45
  model = OpenAIServerModel(
46
  model_id="deepseek-chat",
47
  api_base="https://api.deepseek.com",
48
  api_key=API_KEY
49
  )
50
 
51
- # Load your custom tool and others
52
- currency_tool = get_currency_rate
53
  final_answer = FinalAnswerTool()
 
 
54
 
 
55
  agent = CodeAgent(
56
  model=model,
57
- tools=[currency_tool, final_answer], # Include your tool here
58
  max_steps=3,
59
  verbosity_level=1
60
  )
61
 
62
- #GradioUI(agent).launch()
63
-
64
  examples = """
65
  ### Example Usage
66
  1. **Currency Rate**: Ask for the exchange rate of a currency pair.
@@ -77,9 +77,8 @@ def launch_with_examples(agent):
77
  with gr.Blocks() as demo:
78
  gr.Markdown("# Currency and Time Agent")
79
  gr.Markdown(examples)
80
- GradioUI(agent).render()
81
  demo.launch()
82
 
83
  # Launch the app
84
- launch_with_examples(agent)
85
- #GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, tool, OpenAIServerModel, FinalAnswerTool
2
  import datetime
 
3
  import pytz
4
+ import yfinance as yf
 
5
  import os
6
  from Gradio_UI import GradioUI
7
  import gradio as gr
 
 
8
 
9
+ # Fetch the API key from the environment variable (if needed)
10
  API_KEY = os.getenv("KEY")
11
 
12
  @tool
 
24
  return f"Current {currency_pair} rate: {rate}"
25
  except Exception as e:
26
  return f"Error fetching rate: {str(e)}"
27
+
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
30
  """A tool that fetches the current local time in a specified timezone.
 
40
  except Exception as e:
41
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
42
 
43
+ # Set up the model
44
  model = OpenAIServerModel(
45
  model_id="deepseek-chat",
46
  api_base="https://api.deepseek.com",
47
  api_key=API_KEY
48
  )
49
 
50
+ # Load tools
 
51
  final_answer = FinalAnswerTool()
52
+ currency_tool = get_currency_rate
53
+ time_tool = get_current_time_in_timezone
54
 
55
+ # Create the agent
56
  agent = CodeAgent(
57
  model=model,
58
+ tools=[currency_tool, time_tool, final_answer], # Include your tools here
59
  max_steps=3,
60
  verbosity_level=1
61
  )
62
 
63
+ # Add a Markdown section for example usage
 
64
  examples = """
65
  ### Example Usage
66
  1. **Currency Rate**: Ask for the exchange rate of a currency pair.
 
77
  with gr.Blocks() as demo:
78
  gr.Markdown("# Currency and Time Agent")
79
  gr.Markdown(examples)
80
+ GradioUI(agent).launch() # Use launch() instead of render()
81
  demo.launch()
82
 
83
  # Launch the app
84
+ launch_with_examples(agent)