Spaces:
Sleeping
Sleeping
Update app.py
Browse filesadded email sender. just give ur id, app pwd, recipient's id, subject and body
app.py
CHANGED
|
@@ -4,19 +4,51 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
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
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -51,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import smtplib
|
| 8 |
+
from email.mime.text import MIMEText
|
| 9 |
+
from email.mime.multipart import MIMEMultipart
|
| 10 |
+
from typing import List, Optional
|
| 11 |
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
+
def tool_email_sender(sender:str, pwd:str, reciever:str, subject:str, body:str)-> str:
|
| 17 |
+
"""Sends an email using SMTP
|
|
|
|
| 18 |
Args:
|
| 19 |
+
sender: Sender's email address
|
| 20 |
+
pwd: Sender's email password
|
| 21 |
+
reciever: Recipient's email address
|
| 22 |
+
subject: Email subject line
|
| 23 |
+
body: Main content of the email
|
| 24 |
"""
|
| 25 |
+
|
| 26 |
+
SMTP_SERVER = "smtp.gmail.com"
|
| 27 |
+
SMTP_PORT = 587
|
| 28 |
+
SENDER_EMAIL = sender
|
| 29 |
+
RECIEVER_EMAIL = reciever
|
| 30 |
+
SENDER_PASSWORD = pwd
|
| 31 |
+
try:
|
| 32 |
+
# Create message
|
| 33 |
+
message = MIMEMultipart()
|
| 34 |
+
message["From"] = SENDER_EMAIL
|
| 35 |
+
message["To"] = RECIEVER_EMAIL
|
| 36 |
+
message["Subject"] = subject
|
| 37 |
+
|
| 38 |
+
message.attach(MIMEText(body, "plain"))
|
| 39 |
+
|
| 40 |
+
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
|
| 41 |
+
server.starttls()
|
| 42 |
+
server.login(SENDER_EMAIL, SENDER_PASSWORD)
|
| 43 |
+
|
| 44 |
+
server.sendmail(SENDER_EMAIL, RECIEVER_EMAIL, message.as_string())
|
| 45 |
+
|
| 46 |
+
return f"Email sent successfully to {RECIEVER_EMAIL}"
|
| 47 |
+
|
| 48 |
+
except Exception as e:
|
| 49 |
+
return f"Unexpected error while sending email: {str(e)}"
|
| 50 |
+
|
| 51 |
+
|
| 52 |
|
| 53 |
@tool
|
| 54 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
+
tools=[final_answer, tool_email_sender], ## add your tools here (don't remove final answer)
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|