humza7656 commited on
Commit
afc57ce
·
verified ·
1 Parent(s): 2133afe

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. main.py +75 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use official lightweight Python image
2
+ FROM python:3.11-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Copy requirements first (better caching)
8
+ COPY requirements.txt .
9
+
10
+ # Install dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Copy the rest of the app
14
+ COPY . .
15
+
16
+ # Expose Hugging Face default port
17
+ EXPOSE 7860
18
+
19
+ # Run FastAPI app
20
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import smtplib
2
+ import os
3
+ from fastapi import FastAPI
4
+ from groq import Groq
5
+ from dotenv import load_dotenv
6
+ from datetime import datetime
7
+ import pytz
8
+ from fastapi.middleware.cors import CORSMiddleware
9
+ load_dotenv()
10
+ sender_password=os.getenv("sender_password")
11
+ api_key=os.getenv("api_key")
12
+ client = Groq(api_key=api_key)
13
+ smtp_server = "smtp.gmail.com"
14
+ smtp_port = 587
15
+ sender_email ="muhammadhamzao241@gmail.com"
16
+ sender_password = sender_password
17
+ receiver_email ="muhammadhamzao241@gmail.com"
18
+ pakistan_tz = pytz.timezone('Asia/Karachi')
19
+
20
+
21
+ def get_email_text():
22
+ current_time = datetime.now(pakistan_tz).strftime("%Y-%m-%d %H:%M:%S")
23
+ chat_completion = client.chat.completions.create(
24
+ messages=[
25
+ {
26
+ "role": "system",
27
+ "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."
28
+ },
29
+ # Set a user message for the assistant to respond to.
30
+ {
31
+ "role": "user",
32
+ "content": current_time,
33
+ }
34
+ ],
35
+
36
+ # The language model which will generate the completion.
37
+ model="llama-3.3-70b-versatile"
38
+ )
39
+ return chat_completion.choices[0].message.content
40
+
41
+
42
+
43
+ def send_email():
44
+
45
+
46
+
47
+ message = f"Subject: YOU AND ME\n\n{get_email_text()}"
48
+
49
+ server = smtplib.SMTP(smtp_server, smtp_port)
50
+ server.starttls()
51
+ server.login(sender_email, sender_password)
52
+ server.sendmail(sender_email, receiver_email, message)
53
+ server.quit()
54
+ return 'email deliever'
55
+
56
+
57
+
58
+
59
+
60
+ app=FastAPI()
61
+ app.add_middleware(
62
+ CORSMiddleware,
63
+ allow_credentials=True,
64
+ allow_methods=['*'],
65
+ allow_origins=['*'],
66
+ allow_headers=['*']
67
+ )
68
+ @app.get('/send_email')
69
+
70
+ def check_it():
71
+ return{'Email Send':send_email()}
72
+
73
+
74
+
75
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ python-dotenv
4
+ pytz
5
+ groq