Spaces:
Sleeping
Sleeping
| import smtplib | |
| import os | |
| from fastapi import FastAPI | |
| from groq import Groq | |
| from dotenv import load_dotenv | |
| from datetime import datetime | |
| import pytz | |
| from fastapi.middleware.cors import CORSMiddleware | |
| load_dotenv() | |
| sender_password=os.getenv("sender_password") | |
| api_key=os.getenv("api_key") | |
| client = Groq(api_key=api_key) | |
| smtp_server = "smtp.gmail.com" | |
| smtp_port = 587 | |
| sender_email ="muhammadhamzao241@gmail.com" | |
| sender_password = sender_password | |
| receiver_email ="muhammadhamzao241@gmail.com" | |
| pakistan_tz = pytz.timezone('Asia/Karachi') | |
| def get_email_text(): | |
| current_time = datetime.now(pakistan_tz).strftime("%Y-%m-%d %H:%M:%S") | |
| chat_completion = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": "You are a romantic text generation less than 100 words so you have to do it. You will get time in content and use that time in text generation too." | |
| }, | |
| # Set a user message for the assistant to respond to. | |
| { | |
| "role": "user", | |
| "content": current_time, | |
| } | |
| ], | |
| # The language model which will generate the completion. | |
| model="llama-3.3-70b-versatile" | |
| ) | |
| return chat_completion.choices[0].message.content | |
| def send_email(): | |
| message = f"Subject: YOU AND ME\n\n{get_email_text()}" | |
| server = smtplib.SMTP(smtp_server, smtp_port) | |
| server.starttls() | |
| server.login(sender_email, sender_password) | |
| server.sendmail(sender_email, receiver_email, message) | |
| server.quit() | |
| return 'email deliever' | |
| app=FastAPI() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_credentials=True, | |
| allow_methods=['*'], | |
| allow_origins=['*'], | |
| allow_headers=['*'] | |
| ) | |
| def check_it(): | |
| return{'Email Send':send_email()} | |