cashan commited on
Commit
c613941
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -7,6 +7,64 @@ 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 +113,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ import smtplib
11
+ from email.mime.text import MIMEText
12
+ from email.mime.multipart import MIMEMultipart
13
+ from smolagents.tools import tool
14
+
15
+ # Your Gmail SMTP credentials
16
+ SMTP_SERVER = "smtp.gmail.com"
17
+ SMTP_PORT = 587
18
+ SMTP_USERNAME = "[email protected]" # Replace with your Gmail
19
+ SMTP_PASSWORD = "wbso priu rshv atep" # Replace with your actual App Password
20
+
21
+ @tool
22
+ def send_email_tool(recipient: str, subject: str, body: str, recipient_email: str = None) -> str:
23
+ """A tool that sends an actual email. If the recipient is not in the predefined list, it asks for an email ID.
24
+
25
+ Args:
26
+ recipient: A string representing the contact name or any custom name.
27
+ subject: The subject line of the email.
28
+ body: The main content of the email.
29
+ recipient_email: (Optional) The email address if recipient is not predefined.
30
+
31
+ Returns:
32
+ A success or failure message indicating whether the email was sent.
33
+ """
34
+ # Predefined contact list
35
+ contacts = {
36
+ "shan1": "[email protected]",
37
+ "shan2": "[email protected]",
38
+ "shan3": "[email protected]"
39
+ }
40
+
41
+ # If recipient is in predefined list, use their email
42
+ if recipient in contacts:
43
+ recipient_email = contacts[recipient]
44
+ elif not recipient_email:
45
+ return f"⚠️ Please provide an email address for '{recipient}'."
46
+
47
+ # Create the email
48
+ msg = MIMEMultipart()
49
+ msg["From"] = SMTP_USERNAME
50
+ msg["To"] = recipient_email
51
+ msg["Subject"] = subject
52
+ msg.attach(MIMEText(body, "plain"))
53
+
54
+ try:
55
+ # Connect to Gmail SMTP Server
56
+ server = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
57
+ server.starttls() # Secure the connection
58
+ server.login(SMTP_USERNAME, SMTP_PASSWORD)
59
+ server.sendmail(SMTP_USERNAME, recipient_email, msg.as_string())
60
+ server.quit()
61
+
62
+ return f"✅ Email successfully sent to {recipient_email} with subject '{subject}'."
63
+ except Exception as e:
64
+ return f"❌ Failed to send email: {str(e)}"
65
+
66
+
67
+
68
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
69
  @tool
70
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
113
 
114
  agent = CodeAgent(
115
  model=model,
116
+ tools=[send_email_tool,image_generation_tool,get_current_time_in_timezone,final_answer,DuckDuckGoSearchTool(),useless_advice], ## add your tools here (don't remove final answer)
117
  max_steps=6,
118
  verbosity_level=1,
119
  grammar=None,