Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -237,8 +237,61 @@ def document_data_tool(question):
|
|
| 237 |
# summarized_response = summarize_document(query_response)
|
| 238 |
return query_response
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
-
#
|
| 242 |
def send_email_with_attachment(recipient_email, subject, body, attachment_path):
|
| 243 |
try:
|
| 244 |
from fastapi import FastAPI
|
|
@@ -570,13 +623,21 @@ def answer_question(user_question, chatbot, audio=None):
|
|
| 570 |
# email send
|
| 571 |
if len(user_email) > 0:
|
| 572 |
# Send email with the chart image attached
|
| 573 |
-
|
| 574 |
recipient_email=user_email,
|
| 575 |
subject="Warehouse Inventory Report",
|
| 576 |
body=response.get("output", "").split(":")[0],
|
| 577 |
# attachment_path=chart_path
|
| 578 |
-
attachment_path=
|
| 579 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
|
| 581 |
if "send email to" in user_question:
|
| 582 |
try:
|
|
|
|
| 237 |
# summarized_response = summarize_document(query_response)
|
| 238 |
return query_response
|
| 239 |
|
| 240 |
+
#mailjet API
|
| 241 |
+
def send_email_with_attachment_mailjet(recipient_email, subject, body, attachment_path):
|
| 242 |
+
from mailjet_rest import Client
|
| 243 |
+
import os
|
| 244 |
+
import base64
|
| 245 |
+
|
| 246 |
+
# Replace these with your Mailjet API credentials
|
| 247 |
+
api_key = '9ce0aa1f8eb21d9e2ed2433a5702185b'
|
| 248 |
+
api_secret = '434e366db9b8c421eef99f6f92129fad'
|
| 249 |
+
|
| 250 |
+
# Initialize the Mailjet client
|
| 251 |
+
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
|
| 252 |
+
|
| 253 |
+
# Define the email details with an attachment
|
| 254 |
+
data = {
|
| 255 |
+
'Messages': [
|
| 256 |
+
{
|
| 257 |
+
"From": {
|
| 258 |
+
"Email": "[email protected]",
|
| 259 |
+
"Name": "Redmind Technologies"
|
| 260 |
+
},
|
| 261 |
+
"To": [
|
| 262 |
+
{
|
| 263 |
+
"Email": "recipient_email",
|
| 264 |
+
"Name": "Lakshmi"
|
| 265 |
+
}
|
| 266 |
+
],
|
| 267 |
+
"Subject": subject,
|
| 268 |
+
"TextPart": body,
|
| 269 |
+
|
| 270 |
+
"CustomID": "AppGettingStartedTest",
|
| 271 |
+
"Attachments": [
|
| 272 |
+
{
|
| 273 |
+
"ContentType": "image/png", # Replace with the correct MIME type of your image
|
| 274 |
+
"Filename": "your_image_name.png", # Name of the image as it will appear in the email
|
| 275 |
+
"Base64Content": attachment_path # Base64-encoded image content
|
| 276 |
+
}
|
| 277 |
+
]
|
| 278 |
+
|
| 279 |
+
}
|
| 280 |
+
]
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
# Send the email
|
| 284 |
+
result = mailjet.send.create(data=data)
|
| 285 |
+
print(result)
|
| 286 |
+
# Check if the email was sent successfully
|
| 287 |
+
if result.status_code == 200:
|
| 288 |
+
print("Email sent successfully with attachment!")
|
| 289 |
+
else:
|
| 290 |
+
print(f"Failed to send email. Status code: {result.status_code}")
|
| 291 |
+
print(result.json())
|
| 292 |
+
|
| 293 |
|
| 294 |
+
#smtp lib
|
| 295 |
def send_email_with_attachment(recipient_email, subject, body, attachment_path):
|
| 296 |
try:
|
| 297 |
from fastapi import FastAPI
|
|
|
|
| 623 |
# email send
|
| 624 |
if len(user_email) > 0:
|
| 625 |
# Send email with the chart image attached
|
| 626 |
+
send_email_with_attachment_mailjet(
|
| 627 |
recipient_email=user_email,
|
| 628 |
subject="Warehouse Inventory Report",
|
| 629 |
body=response.get("output", "").split(":")[0],
|
| 630 |
# attachment_path=chart_path
|
| 631 |
+
attachment_path=img_str)
|
| 632 |
)
|
| 633 |
+
# Send email with the chart image attached
|
| 634 |
+
"""send_email_with_attachment(
|
| 635 |
+
recipient_email=user_email,
|
| 636 |
+
subject="Warehouse Inventory Report",
|
| 637 |
+
body=response.get("output", "").split(":")[0],
|
| 638 |
+
# attachment_path=chart_path
|
| 639 |
+
attachment_path=os.getenv("IMAGE_PATH")
|
| 640 |
+
)"""
|
| 641 |
|
| 642 |
if "send email to" in user_question:
|
| 643 |
try:
|