Rename app (1).py to app2.py
Browse files- app (1).py → app2.py +31 -0
app (1).py → app2.py
RENAMED
|
@@ -6,6 +6,9 @@ import os
|
|
| 6 |
import google.generativeai as genai
|
| 7 |
|
| 8 |
import pathlib
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
txt_model = genai.GenerativeModel('gemini-pro')
|
| 11 |
vis_model = genai.GenerativeModel('gemini-pro-vision')
|
|
@@ -38,6 +41,33 @@ def image_to_base64(image_path):
|
|
| 38 |
encoded_string = base64.b64encode(img.read())
|
| 39 |
return encoded_string.decode('utf-8')
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Function that takes User Inputs and displays it on ChatUI
|
| 42 |
def app2_query(history,txt,img):
|
| 43 |
if not img:
|
|
@@ -80,6 +110,7 @@ def app1_response(img):
|
|
| 80 |
else:
|
| 81 |
img = PIL.Image.open(img)
|
| 82 |
response = vis_model.generate_content([txt_prompt_1,img])
|
|
|
|
| 83 |
return response.text
|
| 84 |
|
| 85 |
|
|
|
|
| 6 |
import google.generativeai as genai
|
| 7 |
|
| 8 |
import pathlib
|
| 9 |
+
import smtplib
|
| 10 |
+
from email.mime.multipart import MIMEMultipart
|
| 11 |
+
from email.mime.text import MIMEText
|
| 12 |
|
| 13 |
txt_model = genai.GenerativeModel('gemini-pro')
|
| 14 |
vis_model = genai.GenerativeModel('gemini-pro-vision')
|
|
|
|
| 41 |
encoded_string = base64.b64encode(img.read())
|
| 42 |
return encoded_string.decode('utf-8')
|
| 43 |
|
| 44 |
+
def send_email(message):
|
| 45 |
+
try:
|
| 46 |
+
# SMTP Configuration
|
| 47 |
+
smtp_server = 'smtp.gmail.com'
|
| 48 |
+
port = 587 # For STARTTLS
|
| 49 |
+
sender_email = 'spresent098@gmail.com' # Enter your Gmail address
|
| 50 |
+
receiver_email = 'simonchen2020@icloud.com' # Enter receiver address
|
| 51 |
+
password = os.getenv('GMAIL_PASSWORD') # Retrieve password from environment variable
|
| 52 |
+
|
| 53 |
+
# Create a multipart message and set headers
|
| 54 |
+
msg = MIMEMultipart()
|
| 55 |
+
msg['From'] = sender_email
|
| 56 |
+
msg['To'] = receiver_email
|
| 57 |
+
msg['Subject'] = 'Reminder'
|
| 58 |
+
|
| 59 |
+
# Add body to email
|
| 60 |
+
msg.attach(MIMEText(message, 'plain'))
|
| 61 |
+
|
| 62 |
+
# Send the email
|
| 63 |
+
with smtplib.SMTP(smtp_server, port) as server:
|
| 64 |
+
server.starttls()
|
| 65 |
+
server.login(sender_email, password)
|
| 66 |
+
server.sendmail(sender_email, receiver_email, msg.as_string())
|
| 67 |
+
print('Email sent successfully')
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f'Error occurred: {e}')
|
| 70 |
+
|
| 71 |
# Function that takes User Inputs and displays it on ChatUI
|
| 72 |
def app2_query(history,txt,img):
|
| 73 |
if not img:
|
|
|
|
| 110 |
else:
|
| 111 |
img = PIL.Image.open(img)
|
| 112 |
response = vis_model.generate_content([txt_prompt_1,img])
|
| 113 |
+
send_email(response.text)
|
| 114 |
return response.text
|
| 115 |
|
| 116 |
|