Isaac454 commited on
Commit
14ae1e1
·
verified ·
1 Parent(s): 7933397

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -85
app.py CHANGED
@@ -1,103 +1,21 @@
1
  import os
2
 
3
  HF_TOKEN = os.getenv("HF_TOKEN")
4
- from typing import Optional
5
- from google.oauth2.credentials import Credentials
6
- from google_auth_oauthlib.flow import Flow
7
- from googleapiclient.discovery import build
8
- from google.auth.transport.requests import Request
9
  import os
10
  import datetime
11
  from tools.final_answer import FinalAnswerTool
12
  from Gradio_UI import GradioUI
13
 
14
- from smolagents import tool, LiteLLMModel, ToolCallingAgent # or langchain.tools import tool
15
-
16
- SCOPES = ["https://www.googleapis.com/auth/calendar.events"]
17
- CREDENTIALS_PATH = "/content/client_secret_2_1094244282232-374kgcc6fcm82utq7mudrhs9h8rj10fu.apps.googleusercontent.com (1).json"
18
- TOKEN_PATH = "/content/token.json"
19
-
20
- def get_calendar_service():
21
- creds = None
22
- if os.path.exists(TOKEN_PATH):
23
- creds = Credentials.from_authorized_user_file(TOKEN_PATH, SCOPES)
24
-
25
- if not creds or not creds.valid:
26
- flow = Flow.from_client_secrets_file(
27
- CREDENTIALS_PATH,
28
- scopes=SCOPES,
29
- redirect_uri="https://lena-homocercal-misrely.ngrok-free.dev/rest/oauth2-credential/callback" # <-- your custom URI
30
- )
31
-
32
- auth_url, _ = flow.authorization_url(
33
- access_type="offline",
34
- prompt="consent"
35
- )
36
-
37
- print("Open this URL in your browser:", auth_url)
38
- code = input("Paste the authorization code here: ")
39
-
40
- flow.fetch_token(code=code)
41
- creds = flow.credentials
42
-
43
- with open(TOKEN_PATH, "w") as token:
44
- token.write(creds.to_json())
45
-
46
- return build("calendar", "v3", credentials=creds)
47
-
48
- @tool
49
- def calendar_tool(
50
- title: str,
51
- description: str,
52
- start_datetime: str,
53
- end_datetime: str, ) -> dict:
54
- """
55
- This a tool that creates an event on the calendar
56
-
57
- Args:
58
- title: The is the Heading of the event, what is the event called?
59
- description: The is the description of the event, what is the event about?
60
- start_datetime: ISO format datetime (YYYY-MM-DDTHH:MM:SS)
61
- end_datetime: ISO format datetime (YYYY-MM-DDTHH:MM:SS)
62
-
63
- Return:
64
- dict: This is a dict that tells the user about an event they have stating the date, time, and Title of the event.
65
-
66
- """
67
- service = get_calendar_service()
68
 
69
- event_body = {
70
- "summary": title,
71
- "description": description,
72
- "start": {
73
- "dateTime": start_datetime,
74
- "timeZone": "Africa/Lagos"
75
- },
76
- "end": {
77
- "dateTime": end_datetime,
78
- "timeZone": "Africa/Lagos"
79
- },
80
- }
81
- event = (
82
- service.events()
83
- .insert(calendarId="primary", body=event_body)
84
- .execute()
85
- )
86
- return {
87
- "status": "success",
88
- "event_id": event.get("id"),
89
- "event_link": event.get("htmlLink"),
90
- "title": event.get("summary"),
91
- "start": event["start"]["dateTime"],
92
- "end": event["end"]["dateTime"],
93
- }
94
  final_answer = FinalAnswerTool()
95
  model = LiteLLMModel(
96
  model_id="huggingface/google/gemma-2-2b-it"
97
  )
98
 
99
  agent = ToolCallingAgent(
100
- tools=[calendar_tool],
101
  model=model,
102
  max_steps=10
103
  )
 
1
  import os
2
 
3
  HF_TOKEN = os.getenv("HF_TOKEN")
4
+
 
 
 
 
5
  import os
6
  import datetime
7
  from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
+ from smolagents import tool, LiteLLMModel, ToolCallingAgent, DuckDuckGoSearchTool # or langchain.tools import tool
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  final_answer = FinalAnswerTool()
13
  model = LiteLLMModel(
14
  model_id="huggingface/google/gemma-2-2b-it"
15
  )
16
 
17
  agent = ToolCallingAgent(
18
+ tools=[DuckDuckGoSearchTool()],
19
  model=model,
20
  max_steps=10
21
  )