nguyennp86 commited on
Commit
1291f7a
·
1 Parent(s): d87e64b

Deploy Email Classifier API

Browse files
Files changed (6) hide show
  1. Dockerfile +30 -0
  2. Synthetic_Email_Dataset.csv +401 -0
  3. app.py +339 -0
  4. deploy.py +310 -0
  5. requirements.txt +8 -0
  6. train_model.py +186 -0
Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y \
7
+ build-essential \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ # Copy requirements first to leverage Docker cache
11
+ COPY requirements.txt .
12
+
13
+ # Install Python dependencies
14
+ RUN pip install --no-cache-dir -r requirements.txt
15
+
16
+ # Copy application code
17
+ COPY . .
18
+
19
+ # Create directory for model files
20
+ RUN mkdir -p /app/models
21
+
22
+ # Expose port
23
+ EXPOSE 7860
24
+
25
+ # Health check
26
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
27
+ CMD curl -f http://localhost:7860/health || exit 1
28
+
29
+ # Run the application
30
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
Synthetic_Email_Dataset.csv ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ label,message,topic,intent,tone
2
+ 0,"Hello, You asked for it, so here is the notes. Warm wishes, David",notes,request,formal
3
+ 1,"Good morning, Just sharing the meeting agenda as requested. Cheers, Anna",document,send attachment,informal
4
+ 1,"Good morning, You asked for it, so here is the resume. Regards, Emily",resume,send attachment,formal
5
+ 0,"Dear team, As discussed, I'm sending the manual. Regards, Emily",manual,inform,informal
6
+ 1,"Hi all,Here are the meeting agenda, as promised. Warm wishes, David",meeting agenda,send attachment,informal
7
+ 1,"Dear team, You asked for it, so here is the technical log. Sincerely, Michael",technical log,send attachment,informal
8
+ 0,"Dear team, Attached is the error log you requested. Warm wishes, David",error log,inform,informal
9
+ 1,"Hi all, Kindly review the attached photos. Thanks, Sarah",photos,send attachment,informal
10
+ 0,"Dear team, Attached is the contract you requested. Cheers, Anna",contract,request,informal
11
+ 0,"Good afternoon, Please find attached the invoice. Sincerely, Michael",personal,request,informal
12
+ 1,"Dear team, Please find attached the report. Thanks, Sarah",report,send attachment,formal
13
+ 1,"Dear Paul, As discussed, I'm sending the presentation slides. Regards, Emily",presentation slides,send attachment,informal
14
+ 1,"Dear Hanna, You asked for it, so here is the itinerary. Regards, Emily",itinerary,send attachment,formal
15
+ 1,"Good morning, Just sharing the data analysis as requested. Best regards, John",data analysis,send attachment,informal
16
+ 0,"Hi, As discussed, I'm sending the presentation slides. Cheers, Anna",presentation slides,request,formal
17
+ 0,"Hi, Just sharing the error log as requested. Sincerely, Michael",error log,request,informal
18
+ 1,"Hi all, Kindly review the attached presentation slides. Regards, Emily",presentation slides,send attachment,informal
19
+ 0,"Good morning, As discussed, I'm sending the manual. Cheers, Anna",manual,request,formal
20
+ 0,"Hi, I've attached the notes for your review. Best regards, John",notes,request,formal
21
+ 1,"Good morning, Please find attached the technical log. Cheers, Anna",technical log,send attachment,informal
22
+ 0,"Hi all, Please find attached the presentation slides. Sincerely, Michael",presentation slides,inform,formal
23
+ 0,"Good afternoon,Here are the photos, as promised. Regards, Emily",photos,request,formal
24
+ 1,"Hi, As discussed, I'm sending the proposal. Warm wishes, David",proposal,send attachment,informal
25
+ 1,"Dear team, I've attached the project plan for your review. Best regards, John",project plan,send attachment,informal
26
+ 1,"Hello,Here are the data analysis, as promised. Warm wishes, David",data analysis,send attachment,informal
27
+ 1,"Hi, I've attached the notes for your review. Warm wishes, David",notes,send attachment,informal
28
+ 1,"Hello,Here are the presentation slides, as promised. Sincerely, Michael",presentation slides,send attachment,informal
29
+ 1,"Hi all, I've attached the brochure for your review. Regards, Emily",brochure,send attachment,informal
30
+ 1,"Hi all, Kindly review the attached photos. Best regards, John",photos,send attachment,formal
31
+ 1,"Good afternoon, Please find attached the itinerary. Thanks, Sarah",itinerary,send attachment,informal
32
+ 1,"Dear team,Here are the presentation slides, as promised. Thanks, Sarah",presentation slides,send attachment,informal
33
+ 0,"Dear Alexa, You asked for it, so here is the invoice. Best regards, John",invoice,request,formal
34
+ 1,"Hello, Just sharing the invoice as requested. Sincerely, Michael",invoice,send attachment,informal
35
+ 0,"Good afternoon, Attached is the meeting agenda you requested. Regards, Emily",meeting agenda,inform,formal
36
+ 1,"Hello,Here are the notes, as promised. Warm wishes, David",itinerary,send attachment,informal
37
+ 0,"Good morning, Just sharing the report as requested. Best regards, John",report,request,informal
38
+ 0,"Dear Haley, As discussed, I'm sending the assignment. Thanks, Sarah",assignment,request,informal
39
+ 1,"Hello, I've attached the notes for your review. Best regards, John",notes,send attachment,informal
40
+ 0,"Good afternoon, Please find attached the resume. Cheers, Anna",resume,request,formal
41
+ 1,"Good afternoon, Just sharing the error log as requested. Sincerely, Michael",project plan,send attachment,informal
42
+ 1,"Hi, Please find attached the manual. Warm wishes, David",manual,send attachment,formal
43
+ 1,"Hello, Kindly review the attached invoice. Cheers, Anna",invoice,send attachment,informal
44
+ 1,"Good morning, As discussed, I'm sending the invoice. Sincerely, Michael",invoice,send attachment,formal
45
+ 1,"Good morning, You asked for it, so here is the technical log. Sincerely, Michael",technical log,send attachment,formal
46
+ 1,"Good morning, I've attached the manual for your review. Warm wishes, David",manual,send attachment,formal
47
+ 0,"Dear Jessica, Attached is the resume you requested. Regards, Emily",resume,request,informal
48
+ 1,"Good morning, Just sharing the invoice as requested. Regards, Emily",invoice,send attachment,informal
49
+ 0,"Hi,Here are the invoice, as promised. Cheers, Anna",invoice,request,informal
50
+ 1,"Good morning, Kindly review the attached error log. Best regards, John",error log,send attachment,informal
51
+ 1,"Hi, Please find attached the meeting agenda. Regards, Emily",spreadsheet,send attachment,informal
52
+ 1,"Dear team, I've attached the error log for your review. Cheers, Anna",error log,send attachment,informal
53
+ 0,"Hi all, I've attached the presentation slides for your review. Regards, Emily",presentation slides,inform,informal
54
+ 1,"Good morning, You asked for it, so here is the report. Thanks, Sarah",report,send attachment,formal
55
+ 1,"Dear team, Please find attached the error log. Warm wishes, David",error log,send attachment,formal
56
+ 0,"Hi, Please find attached the invoice. Best regards, John",invoice,inform,informal
57
+ 0,"Hello, As discussed, I'm sending the invoice. Warm wishes, David",invoice,request,informal
58
+ 1,"Good afternoon, Kindly review the attached spreadsheet. Warm wishes, David",spreadsheet,send attachment,formal
59
+ 1,"Hello, Kindly review the attached manual. Sincerely, Michael",manual,send attachment,formal
60
+ 1,"Dear Mat, You asked for it, so here is the resume. Thanks, Sarah",resume,send attachment,informal
61
+ 0,"Hello, I've attached the invoice for your review. Regards, Emily",invoice,request,formal
62
+ 1,"Dear Anna, As discussed, I'm sending the data analysis. Regards, Emily",data analysis,send attachment,informal
63
+ 1,"Good morning, As discussed, I'm sending the manual. Best regards, John",manual,send attachment,formal
64
+ 0,"Hi, Please find attached the spreadsheet. Warm wishes, David",spreadsheet,inform,formal
65
+ 1,"Hello, Just sharing the notes as requested. Regards, Emily",notes,send attachment,informal
66
+ 1,"Hi all, Just sharing the meeting agenda as requested. Cheers, Anna",meeting agenda,send attachment,formal
67
+ 1,"Good afternoon, Attached is the brochure you requested. Best regards, John",brochure,send attachment,informal
68
+ 1,"Hi, You asked for it, so here is the data analysis. Thanks, Sarah",data analysis,send attachment,formal
69
+ 1,"Dear Kai, Please find attached the technical log. Regards, Emily",technical log,send attachment,informal
70
+ 1,"Hello, Kindly review the attached brochure. Best regards, John",brochure,send attachment,formal
71
+ 1,"Hi, Attached is the manual you requested. Warm wishes, David",manual,send attachment,formal
72
+ 1,"Hi all, Attached is the brochure you requested. Thanks, Sarah",brochure,send attachment,informal
73
+ 0,"Good afternoon, Please find attached the manual. Cheers, Anna",project plan,inform,informal
74
+ 1,"Hello, I've attached the technical log for your review. Warm wishes, David",technical log,send attachment,formal
75
+ 1,"Dear team, Attached is the resume you requested. Cheers, Anna",resume,send attachment,informal
76
+ 1,"Dear Chanyeol, Please find attached the technical log. Sincerely, Michael",update,send attachment,informal
77
+ 1,"Hi all, As discussed, I'm sending the proposal. Regards, Emily",proposal,send attachment,informal
78
+ 1,"Good morning, Kindly review the attached invoice. Sincerely, Michael",invoice,send attachment,formal
79
+ 1,"Hi all, Kindly review the attached presentation slides. Warm wishes, David",presentation slides,send attachment,formal
80
+ 1,"Hi, You asked for it, so here is the meeting agenda. Best regards, John",meeting agenda,send attachment,formal
81
+ 0,"Dear Michale, Just sharing the brochure as requested. Warm wishes, David",brochure,request,formal
82
+ 0,"Hello, As discussed, I'm sending the brochure. Sincerely, Michael",brochure,inform,formal
83
+ 0,"Hi, Just sharing the manual as requested. Thanks, Sarah",manual,inform,formal
84
+ 0,"Dear team,Here are the data analysis, as promised. Warm wishes, David",data analysis,request,formal
85
+ 0,"Dear ,Here are the meeting agenda, as promised. Warm wishes, David",meeting agenda,inform,formal
86
+ 1,"Good afternoon, Attached is the itinerary you requested. Regards, Emily",itinerary,send attachment,informal
87
+ 1,"Dear team, You asked for it, so here is the manual. Regards, Emily",manual,send attachment,formal
88
+ 1,"Hello, Attached is the resume you requested. Sincerely, Michael",resume,send attachment,informal
89
+ 1,"Dear Cur, You asked for it, so here is the itinerary. Best regards, John",itinerary,send attachment,informal
90
+ 1,"Hello, As discussed, I'm sending the technical log. Sincerely, Michael",technical log,send attachment,formal
91
+ 0,"Good morning, You asked for it, so here is the meeting agenda. Best regards, John",meeting agenda,request,informal
92
+ 0,"Good morning,Here are the data analysis, as promised. Best regards, John",brochure,inform,formal
93
+ 1,"Dear , You asked for it, so here is the assignment. Regards, Emily",assignment,send attachment,informal
94
+ 1,"Good afternoon, As discussed, I'm sending the invoice. Thanks, Sarah",contract,send attachment,informal
95
+ 1,"Hi, I've attached the proposal for your review. Regards, Emily",proposal,send attachment,formal
96
+ 0,"Good afternoon, Kindly review the attached assignment. Warm wishes, David",assignment,inform,formal
97
+ 1,"Dear team, I've attached the project plan for your review. Regards, Emily",project plan,send attachment,informal
98
+ 1,"Hi, You asked for it, so here is the spreadsheet. Best regards, John",spreadsheet,send attachment,formal
99
+ 1,"Dear Jes, You asked for it, so here is the technical log. Regards, Emily",technical log,send attachment,informal
100
+ 1,"Good morning, Attached is the photos you requested. Cheers, Anna",photos,send attachment,informal
101
+ 1,"Hi all, Just sharing the report as requested. Best regards, John",personal,send attachment,informal
102
+ 1,"Hi, You asked for it, so here is the proposal. Regards, Emily",manual,send attachment,formal
103
+ 0,"Good afternoon, You asked for it, so here is the manual. Thanks, Sarah",manual,inform,informal
104
+ 1,"Dear Josh, As discussed, I'm sending the invoice. Warm wishes, David",invoice,send attachment,formal
105
+ 1,"Good morning, Kindly review the attached proposal. Sincerely, Michael",assignment,send attachment,formal
106
+ 1,"Hello, Just sharing the brochure as requested. Regards, Emily",brochure,send attachment,formal
107
+ 1,"Good morning, Kindly review the attached itinerary. Sincerely, Michael",itinerary,send attachment,formal
108
+ 1,"Dear team, Kindly review the attached photos. Regards, Emily",photos,send attachment,formal
109
+ 1,"Dear Berlin,Here are the itinerary, as promised. Warm wishes, David",itinerary,send attachment,formal
110
+ 1,"Hi all, Kindly review the attached assignment. Warm wishes, David",assignment,send attachment,informal
111
+ 1,"Hi all, Please find attached the spreadsheet. Thanks, Sarah",spreadsheet,send attachment,formal
112
+ 0,"Good afternoon, As discussed, I'm sending the itinerary. Warm wishes, David",itinerary,request,formal
113
+ 1,"Dear Alex, Attached is the invoice you requested. Thanks, Sarah",invoice,send attachment,formal
114
+ 0,"Hello, You asked for it, so here is the presentation slides. Sincerely, Michael",presentation slides,inform,informal
115
+ 1,"Hello,Here are the project plan, as promised. Best regards, John",update,send attachment,formal
116
+ 1,"Dear Susan, Please find attached the notes. Sincerely, Michael",notes,send attachment,formal
117
+ 1,"Dear , As discussed, I'm sending the photos. Sincerely, Michael",photos,send attachment,formal
118
+ 1,"Hi,Here are the itinerary, as promised. Sincerely, Michael",itinerary,send attachment,formal
119
+ 0,"Dear , Kindly review the attached spreadsheet. Thanks, Sarah",spreadsheet,request,informal
120
+ 1,"Hello, I've attached the spreadsheet for your review. Sincerely, Michael",spreadsheet,send attachment,informal
121
+ 1,"Dear , Attached is the report you requested. Cheers, Anna",report,send attachment,formal
122
+ 1,"Hi, Attached is the brochure you requested. Sincerely, Michael",brochure,send attachment,formal
123
+ 1,"Hello, You asked for it, so here is the presentation slides. Sincerely, Michael",presentation slides,send attachment,informal
124
+ 1,"Good morning, Just sharing the brochure as requested. Best regards, John",brochure,send attachment,informal
125
+ 1,"Hi, Kindly review the attached resume. Thanks, Sarah",resume,send attachment,informal
126
+ 1,"Hi, Attached is the meeting agenda you requested. Warm wishes, David",meeting agenda,send attachment,formal
127
+ 1,"Hello, As discussed, I'm sending the assignment. Sincerely, Michael",assignment,send attachment,informal
128
+ 0,"Hi all, Please find attached the resume. Warm wishes, David",resume,request,formal
129
+ 0,"Hello,Here are the technical log, as promised. Best regards, John",technical log,inform,formal
130
+ 1,"Hi all, Just sharing the manual as requested. Thanks, Sarah",manual,send attachment,informal
131
+ 0,"Good afternoon,Here are the technical log, as promised. Sincerely, Michael",technical log,request,formal
132
+ 1,"Dear , Kindly review the attached contract. Warm wishes, David",contract,send attachment,informal
133
+ 1,"Good afternoon, I've attached the brochure for your review. Regards, Emily",brochure,send attachment,formal
134
+ 1,"Dear team, You asked for it, so here is the notes. Sincerely, Michael",notes,send attachment,formal
135
+ 1,"Good afternoon, I've attached the technical log for your review. Thanks, Sarah",technical log,send attachment,informal
136
+ 1,"Hi all, Kindly review the attached brochure. Best regards, John",brochure,send attachment,informal
137
+ 0,"Hello, Attached is the notes you requested. Regards, Emily",notes,inform,formal
138
+ 1,"Dear , Please find attached the notes. Best regards, John",notes,send attachment,formal
139
+ 1,"Dear team,Here are the notes, as promised. Sincerely, Michael",notes,send attachment,formal
140
+ 1,"Dear team, Just sharing the invoice as requested. Best regards, John",invoice,send attachment,formal
141
+ 1,"Dear team, You asked for it, so here is the photos. Thanks, Sarah",photos,send attachment,informal
142
+ 1,"Dear team, Kindly review the attached manual. Best regards, John",manual,send attachment,informal
143
+ 0,"Hi, Please find attached the resume. Warm wishes, David",resume,request,informal
144
+ 0,"Hello, Just sharing the project plan as requested. Cheers, Anna",project plan,request,formal
145
+ 1,"Hi all, Just sharing the brochure as requested. Warm wishes, David",brochure,send attachment,formal
146
+ 1,"Hello, I've attached the resume for your review. Thanks, Sarah",resume,send attachment,informal
147
+ 1,"Dear , You asked for it, so here is the contract. Warm wishes, David",contract,send attachment,formal
148
+ 1,"Hi all,Here are the meeting agenda, as promised. Warm wishes, David",meeting agenda,send attachment,formal
149
+ 0,"Good morning,Here are the notes, as promised. Regards, Emily",notes,inform,formal
150
+ 1,"Dear , I've attached the resume for your review. Best regards, John",resume,send attachment,informal
151
+ 0,"Hello, Kindly review the attached report. Sincerely, Michael",report,request,informal
152
+ 1,"Hi, I've attached the error log for your review. Cheers, Anna",error log,send attachment,informal
153
+ 1,"Hi all, Attached is the data analysis you requested. Sincerely, Michael",data analysis,send attachment,informal
154
+ 0,"Dear , As discussed, I'm sending the assignment. Warm wishes, David",assignment,inform,informal
155
+ 0,"Good afternoon, Please find attached the meeting agenda. Thanks, Sarah",meeting agenda,inform,informal
156
+ 1,"Good afternoon, You asked for it, so here is the assignment. Best regards, John",assignment,send attachment,informal
157
+ 1,"Good morning, You asked for it, so here is the presentation slides. Sincerely, Michael",presentation slides,send attachment,formal
158
+ 1,"Hi, You asked for it, so here is the meeting agenda. Cheers, Anna",meeting agenda,send attachment,informal
159
+ 1,"Good afternoon, Attached is the contract you requested. Warm wishes, David",contract,send attachment,informal
160
+ 1,"Dear , Attached is the spreadsheet you requested. Thanks, Sarah",spreadsheet,send attachment,formal
161
+ 1,"Hi all, You asked for it, so here is the itinerary. Sincerely, Michael",itinerary,send attachment,formal
162
+ 1,"Good afternoon, Please find attached the meeting agenda. Warm wishes, David",meeting agenda,send attachment,informal
163
+ 1,"Hi all,Here are the data analysis, as promised. Best regards, John",data analysis,send attachment,formal
164
+ 1,"Hello,Here are the technical log, as promised. Regards, Emily",technical log,send attachment,formal
165
+ 0,"Hi all, I've attached the notes for your review. Warm wishes, David",assignment,inform,informal
166
+ 1,"Good afternoon, As discussed, I'm sending the error log. Cheers, Anna",error log,send attachment,formal
167
+ 1,"Good morning,Here are the photos, as promised. Regards, Emily",photos,send attachment,informal
168
+ 1,"Dear team,Here are the spreadsheet, as promised. Best regards, John",spreadsheet,send attachment,informal
169
+ 1,"Good morning, Kindly review the attached itinerary. Thanks, Sarah",itinerary,send attachment,informal
170
+ 1,"Good afternoon, You asked for it, so here is the presentation slides. Thanks, Sarah",presentation slides,send attachment,formal
171
+ 1,"Hi all, Attached is the meeting agenda you requested. Thanks, Sarah",spreadsheet,send attachment,informal
172
+ 1,"Dear , You asked for it, so here is the proposal. Warm wishes, David",proposal,send attachment,informal
173
+ 1,"Hi all, You asked for it, so here is the technical log. Regards, Emily",technical log,send attachment,informal
174
+ 1,"Hello, I've attached the brochure for your review. Regards, Emily",brochure,send attachment,formal
175
+ 1,"Hi all, Kindly review the attached resume. Regards, Emily",resume,send attachment,informal
176
+ 1,"Dear , Just sharing the spreadsheet as requested. Regards, Emily",spreadsheet,send attachment,formal
177
+ 1,"Hi all, You asked for it, so here is the report. Regards, Emily",report,send attachment,formal
178
+ 1,"Dear , Attached is the photos you requested. Warm wishes, David",photos,send attachment,informal
179
+ 0,"Dear team, I've attached the presentation slides for your review. Thanks, Sarah",presentation slides,inform,informal
180
+ 1,"Dear , Just sharing the report as requested. Thanks, Sarah",report,send attachment,informal
181
+ 1,"Good afternoon, Just sharing the proposal as requested. Best regards, John",proposal,send attachment,informal
182
+ 1,"Hello, Please find attached the presentation slides. Thanks, Sarah",presentation slides,send attachment,informal
183
+ 1,"Dear , I've attached the notes for your review. Cheers, Anna",technical log,send attachment,formal
184
+ 1,"Good afternoon, Attached is the report you requested. Cheers, Anna",report,send attachment,informal
185
+ 1,"Hi all, Kindly review the attached proposal. Warm wishes, David",proposal,send attachment,formal
186
+ 1,"Hi all, Kindly review the attached contract. Warm wishes, David",project plan,send attachment,formal
187
+ 1,"Dear team, As discussed, I'm sending the notes. Thanks, Sarah",notes,send attachment,formal
188
+ 1,"Hello, I've attached the proposal for your review. Cheers, Anna",proposal,send attachment,formal
189
+ 1,"Hello, Attached is the spreadsheet you requested. Best regards, John",spreadsheet,send attachment,formal
190
+ 0,"Dear team, You asked for it, so here is the presentation slides. Cheers, Anna",presentation slides,request,formal
191
+ 1,"Good afternoon, As discussed, I'm sending the data analysis. Thanks, Sarah",data analysis,send attachment,informal
192
+ 1,"Dear team, Just sharing the manual as requested. Thanks, Sarah",manual,send attachment,informal
193
+ 1,"Hi all, Please find attached the assignment. Cheers, Anna",assignment,send attachment,formal
194
+ 1,"Hi, Please find attached the itinerary. Sincerely, Michael",itinerary,send attachment,informal
195
+ 1,"Hi all, Attached is the technical log you requested. Sincerely, Michael",technical log,send attachment,formal
196
+ 1,"Hello, You asked for it, so here is the report. Regards, Emily",report,send attachment,formal
197
+ 0,"Dear team, Just sharing the resume as requested. Thanks, Sarah",resume,inform,formal
198
+ 1,"Hi,Here are the manual, as promised. Cheers, Anna",manual,send attachment,formal
199
+ 1,"Good afternoon, Please find attached the presentation slides. Regards, Emily",spreadsheet,send attachment,informal
200
+ 0,"Good morning,Here are the assignment, as promised. Regards, Emily",assignment,request,informal
201
+ 1,"Good afternoon, I've attached the presentation slides for your review. Cheers, Anna",presentation slides,send attachment,informal
202
+ 0,"Hi all, Please find attached the technical log. Thanks, Sarah",technical log,request,formal
203
+ 0,"Good afternoon, Kindly review the attached contract. Cheers, Anna",contract,inform,formal
204
+ 1,"Dear , Just sharing the data analysis as requested. Warm wishes, David",data analysis,send attachment,formal
205
+ 1,"Hi, You asked for it, so here is the contract. Warm wishes, David",contract,send attachment,informal
206
+ 1,"Good afternoon, You asked for it, so here is the resume. Sincerely, Michael",resume,send attachment,formal
207
+ 1,"Good afternoon, I've attached the report for your review. Thanks, Sarah",report,send attachment,formal
208
+ 1,"Good morning, Please find attached the notes. Regards, Emily",notes,send attachment,formal
209
+ 1,"Good morning, Just sharing the technical log as requested. Regards, Emily",brochure,send attachment,formal
210
+ 0,"Hi, I've attached the technical log for your review. Warm wishes, David",technical log,request,informal
211
+ 1,"Good morning, Kindly review the attached itinerary. Cheers, Anna",itinerary,send attachment,informal
212
+ 1,"Dear , Attached is the resume you requested. Warm wishes, David",resume,send attachment,informal
213
+ 1,"Hello,Here are the manual, as promised. Best regards, John",manual,send attachment,informal
214
+ 0,"Dear team, Attached is the manual you requested. Sincerely, Michael",manual,request,informal
215
+ 1,"Good morning, Kindly review the attached meeting agenda. Cheers, Anna",meeting agenda,send attachment,formal
216
+ 0,"Dear team, Please find attached the report. Best regards, John",report,inform,informal
217
+ 0,"Dear team, I've attached the itinerary for your review. Best regards, John",itinerary,inform,formal
218
+ 0,"Hello, Attached is the contract you requested. Sincerely, Michael",contract,inform,formal
219
+ 1,"Hi all,Here are the meeting agenda, as promised. Warm wishes, David",meeting agenda,send attachment,informal
220
+ 1,"Dear , You asked for it, so here is the manual. Cheers, Anna",manual,send attachment,formal
221
+ 0,"Dear , Please find attached the assignment. Best regards, John",brochure,request,formal
222
+ 1,"Hi, Please find attached the manual. Warm wishes, David",manual,send attachment,informal
223
+ 1,"Hello, As discussed, I'm sending the data analysis. Regards, Emily",data analysis,send attachment,formal
224
+ 0,"Hi, As discussed, I'm sending the assignment. Thanks, Sarah",assignment,request,informal
225
+ 0,"Hi all, Attached is the itinerary you requested. Sincerely, Michael",itinerary,inform,formal
226
+ 1,"Good afternoon, Attached is the presentation slides you requested. Cheers, Anna",presentation slides,send attachment,formal
227
+ 1,"Dear team, As discussed, I'm sending the invoice. Warm wishes, David",invoice,send attachment,informal
228
+ 1,"Hi, Please find attached the itinerary. Cheers, Anna",itinerary,send attachment,formal
229
+ 0,"Hello, Please find attached the notes. Thanks, Sarah",notes,inform,formal
230
+ 1,"Hello, As discussed, I'm sending the photos. Warm wishes, David",photos,send attachment,informal
231
+ 1,"Good morning, Attached is the error log you requested. Sincerely, Michael",error log,send attachment,formal
232
+ 1,"Dear , Kindly review the attached manual. Warm wishes, David",manual,send attachment,formal
233
+ 1,"Good morning, Attached is the photos you requested. Thanks, Sarah",photos,send attachment,formal
234
+ 1,"Dear , Kindly review the attached error log. Thanks, Sarah",error log,send attachment,formal
235
+ 1,"Dear team, Attached is the itinerary you requested. Thanks, Sarah",itinerary,send attachment,formal
236
+ 0,"Hello, Attached is the technical log you requested. Cheers, Anna",technical log,inform,informal
237
+ 1,"Hello,Here are the resume, as promised. Best regards, John",resume,send attachment,formal
238
+ 1,"Good morning,Here are the spreadsheet, as promised. Thanks, Sarah",spreadsheet,send attachment,formal
239
+ 0,"Hi, I've attached the technical log for your review. Thanks, Sarah",technical log,inform,formal
240
+ 0,"Hi all, Kindly review the attached error log. Best regards, John",error log,request,formal
241
+ 1,"Hello, Please find attached the resume. Cheers, Anna",resume,send attachment,formal
242
+ 1,"Dear , Just sharing the assignment as requested. Cheers, Anna",assignment,send attachment,informal
243
+ 0,"Dear , As discussed, I'm sending the resume. Best regards, John",resume,request,formal
244
+ 0,"Dear team, I've attached the spreadsheet for your review. Best regards, John",spreadsheet,inform,informal
245
+ 1,"Dear , As discussed, I'm sending the brochure. Regards, Emily",brochure,send attachment,formal
246
+ 1,"Dear , Attached is the invoice you requested. Sincerely, Michael",invoice,send attachment,formal
247
+ 1,"Good morning, Kindly review the attached itinerary. Cheers, Anna",itinerary,send attachment,formal
248
+ 1,"Dear team, Please find attached the assignment. Sincerely, Michael",assignment,send attachment,informal
249
+ 0,"Hello, I've attached the report for your review. Sincerely, Michael",report,request,informal
250
+ 0,"Dear , Just sharing the assignment as requested. Best regards, John",assignment,request,informal
251
+ 1,"Dear team, Please find attached the report. Thanks, Sarah",report,send attachment,formal
252
+ 0,"Good morning,Here are the contract, as promised. Regards, Emily",contract,inform,informal
253
+ 1,"Dear team, Please find attached the spreadsheet. Warm wishes, David",spreadsheet,send attachment,informal
254
+ 1,"Hi all, As discussed, I'm sending the spreadsheet. Thanks, Sarah",spreadsheet,send attachment,informal
255
+ 1,"Dear team,Here are the data analysis, as promised. Best regards, John",data analysis,send attachment,informal
256
+ 1,"Good morning, Kindly review the attached photos. Sincerely, Michael",photos,send attachment,informal
257
+ 1,"Good morning, I've attached the contract for your review. Thanks, Sarah",contract,send attachment,formal
258
+ 1,"Hi, Just sharing the invoice as requested. Cheers, Anna",invoice,send attachment,informal
259
+ 0,"Hello, Just sharing the proposal as requested. Cheers, Anna",proposal,request,informal
260
+ 1,"Good afternoon,Here are the invoice, as promised. Best regards, John",invoice,send attachment,informal
261
+ 0,"Dear , Just sharing the resume as requested. Cheers, Anna",resume,inform,formal
262
+ 0,"Dear team, You asked for it, so here is the proposal. Cheers, Anna",proposal,request,informal
263
+ 0,"Hello, Attached is the assignment you requested. Thanks, Sarah",assignment,inform,formal
264
+ 0,"Hi all,Here are the invoice, as promised. Regards, Emily",invoice,request,formal
265
+ 0,"Good morning, You asked for it, so here is the notes. Warm wishes, David",notes,request,formal
266
+ 0,"Hi all, Please find attached the presentation slides. Warm wishes, David",presentation slides,request,informal
267
+ 0,"Good morning, You asked for it, so here is the itinerary. Best regards, John",itinerary,request,informal
268
+ 1,"Good afternoon, You asked for it, so here is the proposal. Sincerely, Michael",presentation slides,send attachment,informal
269
+ 1,"Good afternoon, Kindly review the attached photos. Cheers, Anna",photos,send attachment,informal
270
+ 0,"Dear team, Just sharing the meeting agenda as requested. Warm wishes, David",meeting agenda,inform,formal
271
+ 0,"Hello, Please find attached the data analysis. Thanks, Sarah",data analysis,inform,formal
272
+ 1,"Good morning, Please find attached the resume. Best regards, John",meeting agenda,send attachment,informal
273
+ 0,"Good afternoon,Here are the technical log, as promised. Sincerely, Michael",technical log,request,informal
274
+ 0,"Hello, You asked for it, so here is the meeting agenda. Sincerely, Michael",meeting agenda,request,formal
275
+ 1,"Hi all, Attached is the project plan you requested. Warm wishes, David",project plan,send attachment,formal
276
+ 1,"Hi all, Please find attached the resume. Warm wishes, David",resume,send attachment,formal
277
+ 1,"Hi, Kindly review the attached photos. Sincerely, Michael",photos,send attachment,informal
278
+ 1,"Good afternoon, Kindly review the attached presentation slides. Thanks, Sarah",presentation slides,send attachment,informal
279
+ 1,"Hi all, As discussed, I'm sending the contract. Cheers, Anna",contract,send attachment,informal
280
+ 0,"Good afternoon, Please find attached the technical log. Sincerely, Michael",technical log,request,formal
281
+ 0,"Hi all, Please find attached the itinerary. Best regards, John",itinerary,request,informal
282
+ 1,"Hello,Here are the report, as promised. Sincerely, Michael",report,send attachment,formal
283
+ 1,"Hello, As discussed, I'm sending the assignment. Warm wishes, David",assignment,send attachment,informal
284
+ 1,"Hi all, I've attached the technical log for your review. Regards, Emily",technical log,send attachment,formal
285
+ 0,"Good afternoon, Attached is the notes you requested. Regards, Emily",notes,inform,informal
286
+ 1,"Hello, You asked for it, so here is the invoice. Warm wishes, David",invoice,send attachment,formal
287
+ 0,"Dear team,Here are the itinerary, as promised. Warm wishes, David",itinerary,inform,informal
288
+ 1,"Hi all,Here are the brochure, as promised. Sincerely, Michael",brochure,send attachment,formal
289
+ 1,"Dear team,Here are the invoice, as promised. Thanks, Sarah",invoice,send attachment,informal
290
+ 1,"Hi, You asked for it, so here is the invoice. Thanks, Sarah",invoice,send attachment,informal
291
+ 1,"Hello, As discussed, I'm sending the manual. Thanks, Sarah",manual,send attachment,formal
292
+ 0,"Good afternoon,Here are the spreadsheet, as promised. Best regards, John",spreadsheet,inform,formal
293
+ 0,"Dear Rio, You asked for it, so here is the contract. Best regards, John",contract,inform,formal
294
+ 1,"Hi, Attached is the presentation slides you requested. Cheers, Anna",presentation slides,send attachment,informal
295
+ 1,"Good morning, Kindly review the attached notes. Best regards, John",notes,send attachment,formal
296
+ 1,"Dear team, You asked for it, so here is the notes. Cheers, Anna",proposal,send attachment,formal
297
+ 1,"Good afternoon, As discussed, I'm sending the project plan. Best regards, John",project plan,send attachment,formal
298
+ 0,"Good afternoon, You asked for it, so here is the resume. Best regards, John",resume,request,formal
299
+ 1,"Good morning,Here are the itinerary, as promised. Regards, Emily",itinerary,send attachment,formal
300
+ 1,"Dear Domic, Kindly review the attached notes. Regards, Emily",notes,send attachment,informal
301
+ 1,"Hello, Attached is the error log you requested. Sincerely, Michael",error log,send attachment,formal
302
+ 1,"Good afternoon, You asked for it, so here is the brochure. Sincerely, Michael",brochure,send attachment,informal
303
+ 0,"Hi all, Just sharing the spreadsheet as requested. Sincerely, Michael",spreadsheet,inform,informal
304
+ 0,"Good afternoon,Here are the proposal, as promised. Thanks, Sarah",proposal,inform,informal
305
+ 0,"Good morning, I've attached the data analysis for your review. Cheers, Anna",data analysis,inform,formal
306
+ 1,"Hi, Just sharing the presentation slides as requested. Sincerely, Michael",presentation slides,send attachment,formal
307
+ 1,"Hi, I've attached the manual for your review. Sincerely, Michael",manual,send attachment,formal
308
+ 0,"Hi, Just sharing the assignment as requested. Regards, Emily",assignment,inform,informal
309
+ 1,"Hi, Just sharing the project plan as requested. Thanks, Sarah",project plan,send attachment,formal
310
+ 1,"Hi, As discussed, I'm sending the proposal. Cheers, Anna",proposal,send attachment,informal
311
+ 0,"Hi all, Attached is the notes you requested. Thanks, Sarah",notes,request,informal
312
+ 0,"Dear ,Here are the invoice, as promised. Thanks, Sarah",invoice,inform,formal
313
+ 1,"Good morning,Here are the invoice, as promised. Warm wishes, David",invoice,send attachment,formal
314
+ 1,"Good afternoon, You asked for it, so here is the assignment. Warm wishes, David",itinerary,send attachment,formal
315
+ 0,"Hi all, Attached is the notes you requested. Thanks, Sarah",notes,inform,formal
316
+ 0,"Good morning, Kindly review the attached manual. Regards, Emily",manual,inform,formal
317
+ 1,"Hello, Kindly review the attached contract. Warm wishes, David",contract,send attachment,informal
318
+ 1,"Dear team, As discussed, I'm sending the contract. Cheers, Anna",contract,send attachment,formal
319
+ 1,"Hi all, I've attached the meeting agenda for your review. Warm wishes, David",document,send attachment,formal
320
+ 1,"Hi, Kindly review the attached photos. Best regards, John",photos,send attachment,formal
321
+ 1,"Hi, As discussed, I'm sending the error log. Best regards, John",error log,send attachment,formal
322
+ 0,"Dear team, I've attached the data analysis for your review. Best regards, John",data analysis,request,informal
323
+ 0,"Dear team, Just sharing the data analysis as requested. Thanks, Sarah",data analysis,inform,formal
324
+ 1,"Hi, Please find attached the report. Best regards, John",report,send attachment,informal
325
+ 0,"Hi all, As discussed, I'm sending the spreadsheet. Cheers, Anna",spreadsheet,request,formal
326
+ 0,"Dear , Please find attached the presentation slides. Cheers, Anna",presentation slides,request,informal
327
+ 1,"Hello, You asked for it, so here is the itinerary. Best regards, John",itinerary,send attachment,informal
328
+ 1,"Dear Mic, Just sharing the itinerary as requested. Thanks, Sarah",itinerary,send attachment,informal
329
+ 1,"Good afternoon,Here are the assignment, as promised. Cheers, Anna",assignment,send attachment,informal
330
+ 0,"Hello, Attached is the project plan you requested. Best regards, John",project plan,request,informal
331
+ 1,"Dear Cheerish, I've attached the spreadsheet for your review. Sincerely, Michael",spreadsheet,send attachment,informal
332
+ 0,"Dear Bill, As discussed, I'm sending the report. Regards, Emily",report,inform,informal
333
+ 0,"Dear team, I've attached the contract for your review. Thanks, Sarah",contract,request,informal
334
+ 1,"Hello, Just sharing the brochure as requested. Cheers, Anna",brochure,send attachment,informal
335
+ 1,"Dear Lana, You asked for it, so here is the error log. Warm wishes, David",error log,send attachment,formal
336
+ 0,"Hi all, Please find attached the manual. Best regards, John",manual,inform,informal
337
+ 0,"Dear Taylor, Attached is the itinerary you requested. Thanks, Sarah",itinerary,request,informal
338
+ 0,"Hello, Attached is the contract you requested. Best regards, John",contract,inform,informal
339
+ 0,"Good morning, You asked for it, so here is the data analysis. Warm wishes, David",data analysis,inform,informal
340
+ 1,"Dear team, Attached is the technical log you requested. Regards, Emily",manual,send attachment,informal
341
+ 1,"Good morning, Kindly review the attached project plan. Regards, Emily",project plan,send attachment,formal
342
+ 0,"Dear Justin, You asked for it, so here is the resume. Cheers, Anna",resume,inform,informal
343
+ 1,"Good afternoon,Here are the assignment, as promised. Regards, Emily",assignment,send attachment,formal
344
+ 1,"Hi, You asked for it, so here is the invoice. Best regards, John",invoice,send attachment,informal
345
+ 1,"Good afternoon,Here are the photos, as promised. Sincerely, Michael",itinerary,send attachment,informal
346
+ 0,"Hi, Just sharing the notes as requested. Warm wishes, David",notes,request,informal
347
+ 0,"Dear Weekend, Kindly review the attached proposal. Thanks, Sarah",proposal,request,informal
348
+ 0,"Good morning, You asked for it, so here is the assignment. Regards, Emily",assignment,inform,formal
349
+ 1,"Hi all, Just sharing the resume as requested. Regards, Emily",resume,send attachment,formal
350
+ 0,"Good morning, Kindly review the attached manual. Regards, Emily",manual,request,informal
351
+ 0,"Hi all, Attached is the technical log you requested. Warm wishes, David",technical log,inform,formal
352
+ 1,"Good morning, I've attached the spreadsheet for your review. Regards, Emily",spreadsheet,send attachment,formal
353
+ 0,"Good afternoon, As discussed, I'm sending the proposal. Thanks, Sarah",proposal,inform,formal
354
+ 1,"Dear Bernard, Kindly review the attached notes. Sincerely, Michael",notes,send attachment,informal
355
+ 1,"Good morning, Kindly review the attached invoice. Regards, Emily",invoice,send attachment,informal
356
+ 1,"Hi all, Kindly review the attached meeting agenda. Sincerely, Michael",meeting agenda,send attachment,informal
357
+ 1,"Hi, Just sharing the contract as requested. Best regards, John",contract,send attachment,formal
358
+ 0,"Hi all, As discussed, I'm sending the report. Warm wishes, David",report,inform,formal
359
+ 0,"Good morning, You asked for it, so here is the project plan. Sincerely, Michael",project plan,inform,formal
360
+ 0,"Dear team, Just sharing the assignment as requested. Thanks, Sarah",assignment,inform,informal
361
+ 1,"Good afternoon, Kindly review the attached proposal. Warm wishes, David",proposal,send attachment,informal
362
+ 0,"Dear Joe, Just sharing the manual as requested. Warm wishes, David",manual,request,informal
363
+ 0,"Dear Josh, Kindly review the attached data analysis. Sincerely, Michael",data analysis,inform,informal
364
+ 1,"Hi, I've attached the report for your review. Thanks, Sarah",report,send attachment,informal
365
+ 1,"Hi, I've attached the project plan for your review. Best regards, John",project plan,send attachment,formal
366
+ 0,"Hi, You asked for it, so here is the assignment. Cheers, Anna",assignment,inform,informal
367
+ 1,"Good afternoon,Here are the contract, as promised. Best regards, John",contract,send attachment,informal
368
+ 0,"Hi, Just sharing the notes as requested. Thanks, Sarah",notes,request,formal
369
+ 1,"Hello, You asked for it, so here is the photos. Thanks, Sarah",spreadsheet,send attachment,formal
370
+ 1,"Hi all, Kindly review the attached brochure. Thanks, Sarah",brochure,send attachment,formal
371
+ 0,"Dear Jolie, I've attached the assignment for your review. Sincerely, Michael",project plan,inform,informal
372
+ 1,"Dear William, Please find attached the data analysis. Thanks, Sarah",data analysis,send attachment,formal
373
+ 0,"Good morning, You asked for it, so here is the meeting agenda. Regards, Emily",meeting agenda,inform,informal
374
+ 1,"Hello, As discussed, I'm sending the invoice. Sincerely, Michael",invoice,send attachment,informal
375
+ 1,"Dear Will,Here are the itinerary, as promised. Regards, Emily",itinerary,send attachment,formal
376
+ 1,"Hello, As discussed, I'm sending the photos. Best regards, John",photos,send attachment,informal
377
+ 1,"Hi, Just sharing the meeting agenda as requested. Best regards, John",meeting agenda,send attachment,formal
378
+ 1,"Hi all,Here are the presentation slides, as promised. Regards, Emily",presentation slides,send attachment,informal
379
+ 1,"Hi, You asked for it, so here is the spreadsheet. Thanks, Sarah",spreadsheet,send attachment,informal
380
+ 1,"Hi all, Please find attached the resume. Sincerely, Michael",technical log,send attachment,formal
381
+ 1,"Hi, Please find attached the itinerary. Cheers, Anna",itinerary,send attachment,formal
382
+ 1,"Dear team,Here are the assignment, as promised. Best regards, John",assignment,send attachment,formal
383
+ 0,"Hi all, You asked for it, so here is the meeting agenda. Regards, Emily",meeting agenda,inform,informal
384
+ 1,"Dear team, Attached is the manual you requested. Sincerely, Michael",manual,send attachment,informal
385
+ 1,"Good morning, Please find attached the resume. Regards, Emily",resume,send attachment,formal
386
+ 1,"Good morning, You asked for it, so here is the notes. Warm wishes, David",notes,send attachment,informal
387
+ 0,"Dear Jas, Please find attached the technical log. Sincerely, Michael",technical log,request,formal
388
+ 0,"Dear team, You asked for it, so here is the report. Warm wishes, David",report,request,informal
389
+ 1,"Dear Leo, As discussed, I'm sending the data analysis. Sincerely, Michael",data analysis,send attachment,informal
390
+ 1,"Dear Lio, Attached is the spreadsheet you requested. Thanks, Sarah",spreadsheet,send attachment,formal
391
+ 1,"Hi all, As discussed, I'm sending the presentation slides. Cheers, Anna",presentation slides,send attachment,informal
392
+ 1,"Hi, Attached is the brochure you requested. Best regards, John",brochure,send attachment,informal
393
+ 1,"Hello, As discussed, I'm sending the presentation slides. Regards, Emily",presentation slides,send attachment,informal
394
+ 0,"Hi, Please find attached the project plan. Warm wishes, David",project plan,inform,formal
395
+ 0,"Good afternoon,Here are the photos, as promised. Best regards, John",photos,inform,formal
396
+ 1,"Good afternoon, As discussed, I'm sending the brochure. Regards, Emily",brochure,send attachment,formal
397
+ 1,"Dear Nah, Please find attached the manual. Best regards, John",manual,send attachment,informal
398
+ 0,"Hello, Kindly review the attached assignment. Thanks, Sarah",assignment,request,informal
399
+ 1,"Hello, Please find attached the photos. Warm wishes, David",photos,send attachment,formal
400
+ 1,"Dear Nick, Please find attached the project plan. Cheers, Anna",project plan,send attachment,formal
401
+ 1,"Hi, Attached is the contract you requested. Best regards, John",contract,send attachment,formal
app.py ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from fastapi.responses import HTMLResponse
4
+ from pydantic import BaseModel
5
+ import joblib
6
+ import pandas as pd
7
+ import numpy as np
8
+ from sklearn.feature_extraction.text import TfidfVectorizer
9
+ from sklearn.naive_bayes import MultinomialNB
10
+ from sklearn.pipeline import Pipeline
11
+ from sklearn.model_selection import train_test_split
12
+ from sklearn.metrics import classification_report, accuracy_score
13
+ import re
14
+ import os
15
+ from typing import List, Dict, Any
16
+ import logging
17
+
18
+ # Configure logging
19
+ logging.basicConfig(level=logging.INFO)
20
+ logger = logging.getLogger(__name__)
21
+
22
+ # Initialize FastAPI app
23
+ app = FastAPI(
24
+ title="Email Attachment Classifier API",
25
+ description="API to classify whether an email has attachments or not using Naive Bayes",
26
+ version="1.0.0",
27
+ docs_url="/docs",
28
+ redoc_url="/redoc"
29
+ )
30
+
31
+ # Add CORS middleware
32
+ app.add_middleware(
33
+ CORSMiddleware,
34
+ allow_origins=["*"],
35
+ allow_credentials=True,
36
+ allow_methods=["*"],
37
+ allow_headers=["*"],
38
+ )
39
+
40
+ # Pydantic models
41
+ class EmailInput(BaseModel):
42
+ message: str
43
+
44
+ class EmailBatchInput(BaseModel):
45
+ messages: List[str]
46
+
47
+ class PredictionResponse(BaseModel):
48
+ message: str
49
+ prediction: int
50
+ prediction_label: str
51
+ confidence: float
52
+ probabilities: Dict[str, float]
53
+
54
+ class BatchPredictionResponse(BaseModel):
55
+ predictions: List[PredictionResponse]
56
+
57
+ class ModelInfo(BaseModel):
58
+ model_type: str
59
+ accuracy: float
60
+ feature_count: int
61
+ training_samples: int
62
+
63
+ # Global variables
64
+ model_pipeline = None
65
+ model_info = None
66
+
67
+ def preprocess_text(text: str) -> str:
68
+ """Preprocess email text"""
69
+ # Convert to lowercase
70
+ text = text.lower()
71
+ # Remove extra whitespace
72
+ text = re.sub(r'\s+', ' ', text)
73
+ # Remove special characters but keep basic punctuation
74
+ text = re.sub(r'[^\w\s,.\-!?]', ' ', text)
75
+ return text.strip()
76
+
77
+ def load_and_train_model():
78
+ """Load data and train the Naive Bayes model"""
79
+ global model_pipeline, model_info
80
+
81
+ try:
82
+ # Load the dataset (assuming it's in the same directory)
83
+ if os.path.exists('Synthetic_Email_Dataset.csv'):
84
+ df = pd.read_csv('Synthetic_Email_Dataset.csv')
85
+ else:
86
+ logger.warning("Dataset file not found, creating sample data")
87
+ # Create sample data for demonstration
88
+ sample_data = {
89
+ 'label': [0, 1, 0, 1] * 100,
90
+ 'message': [
91
+ "Hello, You asked for it, so here is the notes. Warm wishes, David",
92
+ "Good morning, Just sharing the meeting agenda as requested. Cheers, Anna",
93
+ "Dear team, As discussed, I'm sending the manual. Regards, Emily",
94
+ "Hi all, Please find attached the project plan. Thanks, Michael"
95
+ ] * 100
96
+ }
97
+ df = pd.DataFrame(sample_data)
98
+
99
+ # Preprocess messages
100
+ df['processed_message'] = df['message'].apply(preprocess_text)
101
+
102
+ # Split data
103
+ X = df['processed_message']
104
+ y = df['label']
105
+
106
+ X_train, X_test, y_train, y_test = train_test_split(
107
+ X, y, test_size=0.2, random_state=42, stratify=y
108
+ )
109
+
110
+ # Create pipeline
111
+ model_pipeline = Pipeline([
112
+ ('tfidf', TfidfVectorizer(
113
+ max_features=1000,
114
+ ngram_range=(1, 2),
115
+ stop_words='english',
116
+ lowercase=True,
117
+ min_df=1,
118
+ max_df=0.95
119
+ )),
120
+ ('classifier', MultinomialNB(alpha=1.0))
121
+ ])
122
+
123
+ # Train model
124
+ logger.info("Training Naive Bayes model...")
125
+ model_pipeline.fit(X_train, y_train)
126
+
127
+ # Evaluate model
128
+ y_pred = model_pipeline.predict(X_test)
129
+ accuracy = accuracy_score(y_test, y_pred)
130
+
131
+ # Store model info
132
+ model_info = ModelInfo(
133
+ model_type="Multinomial Naive Bayes",
134
+ accuracy=round(accuracy, 4),
135
+ feature_count=model_pipeline.named_steps['tfidf'].vocabulary_.__len__(),
136
+ training_samples=len(X_train)
137
+ )
138
+
139
+ logger.info(f"Model trained successfully with accuracy: {accuracy:.4f}")
140
+ logger.info(f"Feature count: {model_info.feature_count}")
141
+
142
+ # Save model
143
+ joblib.dump(model_pipeline, 'email_classifier_model.pkl')
144
+ logger.info("Model saved successfully")
145
+
146
+ return True
147
+
148
+ except Exception as e:
149
+ logger.error(f"Error in training model: {str(e)}")
150
+ return False
151
+
152
+ def load_pretrained_model():
153
+ """Load pretrained model if available"""
154
+ global model_pipeline, model_info
155
+
156
+ try:
157
+ if os.path.exists('email_classifier_model.pkl'):
158
+ model_pipeline = joblib.load('email_classifier_model.pkl')
159
+ logger.info("Pretrained model loaded successfully")
160
+
161
+ # Set default model info if not available
162
+ if model_info is None:
163
+ model_info = ModelInfo(
164
+ model_type="Multinomial Naive Bayes",
165
+ accuracy=0.92, # Default value
166
+ feature_count=len(model_pipeline.named_steps['tfidf'].vocabulary_),
167
+ training_samples=320 # Default value
168
+ )
169
+ return True
170
+ except Exception as e:
171
+ logger.error(f"Error loading pretrained model: {str(e)}")
172
+
173
+ return False
174
+
175
+ @app.on_event("startup")
176
+ async def startup_event():
177
+ """Initialize model on startup"""
178
+ logger.info("Starting Email Classifier API...")
179
+
180
+ # Try to load pretrained model first
181
+ if not load_pretrained_model():
182
+ # If no pretrained model, train new one
183
+ if not load_and_train_model():
184
+ logger.error("Failed to initialize model")
185
+
186
+ @app.get("/", response_class=HTMLResponse)
187
+ async def root():
188
+ """Root endpoint with API documentation"""
189
+ html_content = """
190
+ <!DOCTYPE html>
191
+ <html>
192
+ <head>
193
+ <title>Email Attachment Classifier API</title>
194
+ <style>
195
+ body { font-family: Arial, sans-serif; margin: 40px; }
196
+ .header { color: #2c3e50; }
197
+ .endpoint { background-color: #f8f9fa; padding: 15px; margin: 10px 0; border-radius: 5px; }
198
+ .method { color: #27ae60; font-weight: bold; }
199
+ code { background-color: #e9ecef; padding: 2px 4px; border-radius: 3px; }
200
+ </style>
201
+ </head>
202
+ <body>
203
+ <h1 class="header">📧 Email Attachment Classifier API</h1>
204
+ <p>This API classifies whether an email message indicates an attachment or not using Naive Bayes classifier.</p>
205
+
206
+ <h2>Available Endpoints:</h2>
207
+
208
+ <div class="endpoint">
209
+ <h3><span class="method">GET</span> /info</h3>
210
+ <p>Get model information and statistics</p>
211
+ </div>
212
+
213
+ <div class="endpoint">
214
+ <h3><span class="method">POST</span> /predict</h3>
215
+ <p>Predict single email message</p>
216
+ <p><strong>Body:</strong> <code>{"message": "Your email content here"}</code></p>
217
+ </div>
218
+
219
+ <div class="endpoint">
220
+ <h3><span class="method">POST</span> /predict-batch</h3>
221
+ <p>Predict multiple email messages</p>
222
+ <p><strong>Body:</strong> <code>{"messages": ["Email 1", "Email 2", ...]}</code></p>
223
+ </div>
224
+
225
+ <div class="endpoint">
226
+ <h3><span class="method">GET</span> /health</h3>
227
+ <p>Check API health status</p>
228
+ </div>
229
+
230
+ <h2>Interactive Documentation:</h2>
231
+ <p>Visit <a href="/docs">/docs</a> for Swagger UI or <a href="/redoc">/redoc</a> for ReDoc</p>
232
+
233
+ <h2>Labels:</h2>
234
+ <ul>
235
+ <li><strong>0:</strong> No attachment mentioned</li>
236
+ <li><strong>1:</strong> Attachment mentioned</li>
237
+ </ul>
238
+ </body>
239
+ </html>
240
+ """
241
+ return HTMLResponse(content=html_content, status_code=200)
242
+
243
+ @app.get("/health")
244
+ async def health_check():
245
+ """Health check endpoint"""
246
+ if model_pipeline is None:
247
+ return {"status": "unhealthy", "message": "Model not loaded"}
248
+ return {"status": "healthy", "message": "API is running"}
249
+
250
+ @app.get("/info", response_model=ModelInfo)
251
+ async def get_model_info():
252
+ """Get model information"""
253
+ if model_info is None:
254
+ raise HTTPException(status_code=503, detail="Model not initialized")
255
+ return model_info
256
+
257
+ @app.post("/predict", response_model=PredictionResponse)
258
+ async def predict_single(email: EmailInput):
259
+ """Predict single email message"""
260
+ if model_pipeline is None:
261
+ raise HTTPException(status_code=503, detail="Model not loaded")
262
+
263
+ try:
264
+ # Preprocess input
265
+ processed_message = preprocess_text(email.message)
266
+
267
+ # Make prediction
268
+ prediction = model_pipeline.predict([processed_message])[0]
269
+ probabilities = model_pipeline.predict_proba([processed_message])[0]
270
+
271
+ # Prepare response
272
+ prediction_label = "Has attachment" if prediction == 1 else "No attachment"
273
+ confidence = float(max(probabilities))
274
+
275
+ prob_dict = {
276
+ "no_attachment": float(probabilities[0]),
277
+ "has_attachment": float(probabilities[1])
278
+ }
279
+
280
+ return PredictionResponse(
281
+ message=email.message,
282
+ prediction=int(prediction),
283
+ prediction_label=prediction_label,
284
+ confidence=confidence,
285
+ probabilities=prob_dict
286
+ )
287
+
288
+ except Exception as e:
289
+ logger.error(f"Prediction error: {str(e)}")
290
+ raise HTTPException(status_code=500, detail=f"Prediction failed: {str(e)}")
291
+
292
+ @app.post("/predict-batch", response_model=BatchPredictionResponse)
293
+ async def predict_batch(emails: EmailBatchInput):
294
+ """Predict multiple email messages"""
295
+ if model_pipeline is None:
296
+ raise HTTPException(status_code=503, detail="Model not loaded")
297
+
298
+ if len(emails.messages) > 100:
299
+ raise HTTPException(status_code=400, detail="Maximum 100 messages per batch")
300
+
301
+ try:
302
+ predictions = []
303
+
304
+ # Preprocess all messages
305
+ processed_messages = [preprocess_text(msg) for msg in emails.messages]
306
+
307
+ # Make batch predictions
308
+ batch_predictions = model_pipeline.predict(processed_messages)
309
+ batch_probabilities = model_pipeline.predict_proba(processed_messages)
310
+
311
+ # Prepare responses
312
+ for i, (message, prediction, probabilities) in enumerate(
313
+ zip(emails.messages, batch_predictions, batch_probabilities)
314
+ ):
315
+ prediction_label = "Has attachment" if prediction == 1 else "No attachment"
316
+ confidence = float(max(probabilities))
317
+
318
+ prob_dict = {
319
+ "no_attachment": float(probabilities[0]),
320
+ "has_attachment": float(probabilities[1])
321
+ }
322
+
323
+ predictions.append(PredictionResponse(
324
+ message=message,
325
+ prediction=int(prediction),
326
+ prediction_label=prediction_label,
327
+ confidence=confidence,
328
+ probabilities=prob_dict
329
+ ))
330
+
331
+ return BatchPredictionResponse(predictions=predictions)
332
+
333
+ except Exception as e:
334
+ logger.error(f"Batch prediction error: {str(e)}")
335
+ raise HTTPException(status_code=500, detail=f"Batch prediction failed: {str(e)}")
336
+
337
+ if __name__ == "__main__":
338
+ import uvicorn
339
+ uvicorn.run(app, host="0.0.0.0", port=7860)
deploy.py ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Automated deployment script for Hugging Face Spaces
4
+ """
5
+
6
+ import os
7
+ import subprocess
8
+ import sys
9
+ import shutil
10
+ from pathlib import Path
11
+ import json
12
+ import requests
13
+ from datetime import datetime
14
+
15
+ class HuggingFaceDeployer:
16
+ def __init__(self, username: str, space_name: str, token: str = None):
17
+ self.username = username
18
+ self.space_name = space_name
19
+ self.token = token
20
+ self.space_url = f"https://huggingface.co/spaces/{username}/{space_name}"
21
+ self.git_url = f"https://huggingface.co/spaces/{username}/{space_name}.git"
22
+
23
+ def check_requirements(self):
24
+ """Check if all required files exist"""
25
+ required_files = [
26
+ 'app.py',
27
+ 'requirements.txt',
28
+ 'Dockerfile',
29
+ 'README.md',
30
+ 'Synthetic_Email_Dataset.csv'
31
+ ]
32
+
33
+ missing_files = []
34
+ for file in required_files:
35
+ if not os.path.exists(file):
36
+ missing_files.append(file)
37
+
38
+ if missing_files:
39
+ print(f"❌ Missing required files: {', '.join(missing_files)}")
40
+ return False
41
+
42
+ print("✅ All required files found")
43
+ return True
44
+
45
+ def setup_huggingface_space(self):
46
+ """Create Hugging Face Space via API"""
47
+ if not self.token:
48
+ print("⚠️ No Hugging Face token provided. You'll need to create the space manually.")
49
+ print(f"Go to: https://huggingface.co/new-space")
50
+ input("Press Enter after creating the space...")
51
+ return True
52
+
53
+ headers = {"Authorization": f"Bearer {self.token}"}
54
+ data = {
55
+ "type": "space",
56
+ "name": self.space_name,
57
+ "sdk": "docker",
58
+ "private": False
59
+ }
60
+
61
+ response = requests.post(
62
+ f"https://huggingface.co/api/repos/create",
63
+ headers=headers,
64
+ json=data
65
+ )
66
+
67
+ if response.status_code == 201:
68
+ print(f"✅ Space created successfully: {self.space_url}")
69
+ return True
70
+ elif response.status_code == 409:
71
+ print(f"ℹ️ Space already exists: {self.space_url}")
72
+ return True
73
+ else:
74
+ print(f"❌ Failed to create space: {response.text}")
75
+ return False
76
+
77
+ def prepare_files(self):
78
+ """Prepare files for deployment"""
79
+ print("📁 Preparing files...")
80
+
81
+ # Create README.md with proper header
82
+ readme_header = f'''---
83
+ title: {self.space_name.replace('-', ' ').title()}
84
+ emoji: 📧
85
+ colorFrom: blue
86
+ colorTo: green
87
+ sdk: docker
88
+ app_port: 7860
89
+ pinned: false
90
+ license: mit
91
+ tags:
92
+ - email-classification
93
+ - naive-bayes
94
+ - text-classification
95
+ - nlp
96
+ - fastapi
97
+ ---
98
+
99
+ '''
100
+
101
+ # Read existing README and add header
102
+ if os.path.exists('README.md'):
103
+ with open('README.md', 'r', encoding='utf-8') as f:
104
+ existing_content = f.read()
105
+
106
+ # Remove existing header if present
107
+ if existing_content.startswith('---'):
108
+ parts = existing_content.split('---', 2)
109
+ if len(parts) > 2:
110
+ existing_content = parts[2].strip()
111
+
112
+ with open('README.md', 'w', encoding='utf-8') as f:
113
+ f.write(readme_header + existing_content)
114
+
115
+ print("✅ Files prepared")
116
+ return True
117
+
118
+ def clone_and_deploy(self):
119
+ """Clone the space repository and deploy"""
120
+ print("🔄 Cloning repository...")
121
+
122
+ # Create temporary directory
123
+ temp_dir = f"temp_{self.space_name}"
124
+ if os.path.exists(temp_dir):
125
+ shutil.rmtree(temp_dir)
126
+
127
+ try:
128
+ # Clone the repository
129
+ result = subprocess.run([
130
+ 'git', 'clone', self.git_url, temp_dir
131
+ ], capture_output=True, text=True)
132
+
133
+ if result.returncode != 0:
134
+ print(f"❌ Failed to clone repository: {result.stderr}")
135
+ return False
136
+
137
+ # Copy files to the cloned repository
138
+ files_to_copy = [
139
+ 'app.py',
140
+ 'requirements.txt',
141
+ 'Dockerfile',
142
+ 'README.md',
143
+ 'train_model.py',
144
+ 'Synthetic_Email_Dataset.csv'
145
+ ]
146
+
147
+ for file in files_to_copy:
148
+ if os.path.exists(file):
149
+ shutil.copy2(file, temp_dir)
150
+ print(f"📄 Copied {file}")
151
+
152
+ # Change to the repository directory
153
+ os.chdir(temp_dir)
154
+
155
+ # Configure git
156
+ subprocess.run(['git', 'config', 'user.email', '[email protected]'])
157
+ subprocess.run(['git', 'config', 'user.name', 'Auto Deployer'])
158
+
159
+ # Add all files
160
+ subprocess.run(['git', 'add', '.'])
161
+
162
+ # Commit changes
163
+ commit_message = f"Deploy Email Classifier API - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
164
+ result = subprocess.run(['git', 'commit', '-m', commit_message],
165
+ capture_output=True, text=True)
166
+
167
+ if result.returncode != 0:
168
+ print(f"ℹ️ Nothing to commit or commit failed: {result.stderr}")
169
+
170
+ # Push changes
171
+ if self.token:
172
+ # Use token for authentication
173
+ auth_url = self.git_url.replace('https://', f'https://oauth2:{self.token}@')
174
+ result = subprocess.run(['git', 'push', auth_url, 'main'],
175
+ capture_output=True, text=True)
176
+ else:
177
+ result = subprocess.run(['git', 'push', 'origin', 'main'],
178
+ capture_output=True, text=True)
179
+
180
+ if result.returncode == 0:
181
+ print("✅ Successfully pushed to Hugging Face!")
182
+ print(f"🚀 Your API will be available at: {self.space_url}")
183
+ return True
184
+ else:
185
+ print(f"❌ Failed to push: {result.stderr}")
186
+ return False
187
+
188
+ except Exception as e:
189
+ print(f"❌ Deployment failed: {str(e)}")
190
+ return False
191
+ finally:
192
+ # Clean up
193
+ os.chdir('..')
194
+ if os.path.exists(temp_dir):
195
+ shutil.rmtree(temp_dir)
196
+
197
+ def test_deployment(self):
198
+ """Test the deployed API"""
199
+ print("🧪 Testing deployed API...")
200
+
201
+ api_url = f"{self.space_url.replace('/spaces/', '/spaces/')}"
202
+
203
+ # Wait a bit for deployment
204
+ import time
205
+ print("⏳ Waiting for deployment to complete...")
206
+ time.sleep(30)
207
+
208
+ try:
209
+ # Test health endpoint
210
+ response = requests.get(f"{api_url}/health", timeout=30)
211
+ if response.status_code == 200:
212
+ print("✅ Health check passed")
213
+
214
+ # Test prediction endpoint
215
+ test_response = requests.post(
216
+ f"{api_url}/predict",
217
+ json={"message": "Please find attached the document."},
218
+ timeout=30
219
+ )
220
+
221
+ if test_response.status_code == 200:
222
+ result = test_response.json()
223
+ print(f"✅ Prediction test passed: {result['prediction_label']}")
224
+ return True
225
+ else:
226
+ print(f"❌ Prediction test failed: {test_response.status_code}")
227
+ else:
228
+ print(f"❌ Health check failed: {response.status_code}")
229
+
230
+ except requests.exceptions.RequestException as e:
231
+ print(f"⚠️ API not yet accessible (this is normal for new deployments): {str(e)}")
232
+ print("🕐 The API may take a few minutes to become available")
233
+
234
+ return False
235
+
236
+ def deploy(self):
237
+ """Full deployment process"""
238
+ print("🚀 Starting deployment to Hugging Face Spaces...")
239
+ print(f"📦 Space: {self.space_url}")
240
+ print("="*60)
241
+
242
+ # Check requirements
243
+ if not self.check_requirements():
244
+ return False
245
+
246
+ # Setup Hugging Face Space
247
+ if not self.setup_huggingface_space():
248
+ return False
249
+
250
+ # Prepare files
251
+ if not self.prepare_files():
252
+ return False
253
+
254
+ # Deploy
255
+ if not self.clone_and_deploy():
256
+ return False
257
+
258
+ print("\n" + "="*60)
259
+ print("🎉 DEPLOYMENT COMPLETED!")
260
+ print("="*60)
261
+ print(f"📧 API URL: {self.space_url}")
262
+ print(f"📚 Documentation: {self.space_url}/docs")
263
+ print(f"🔍 Interactive API: {self.space_url}/redoc")
264
+ print("\n⏳ Note: It may take a few minutes for the API to become fully available.")
265
+
266
+ # Test deployment
267
+ self.test_deployment()
268
+
269
+ return True
270
+
271
+ def main():
272
+ """Main deployment function"""
273
+ print("🔧 Hugging Face Spaces Deployment Tool")
274
+ print("="*40)
275
+
276
+ # Get user input
277
+ username = input("Enter your Hugging Face username: ").strip()
278
+ if not username:
279
+ print("❌ Username is required")
280
+ sys.exit(1)
281
+
282
+ space_name = input("Enter space name (e.g., email-classifier-api): ").strip()
283
+ if not space_name:
284
+ print("❌ Space name is required")
285
+ sys.exit(1)
286
+
287
+ token = input("Enter your Hugging Face token (optional, press Enter to skip): ").strip()
288
+ if not token:
289
+ print("ℹ️ No token provided. You'll need to create the space manually.")
290
+
291
+ # Create deployer and deploy
292
+ deployer = HuggingFaceDeployer(username, space_name, token)
293
+
294
+ if deployer.deploy():
295
+ print("\n✅ Deployment successful!")
296
+ print("\n📋 Next steps:")
297
+ print("1. Wait 2-3 minutes for the build to complete")
298
+ print("2. Check the build logs in your Hugging Face Space")
299
+ print("3. Test your API endpoints")
300
+ print("4. Share your API with others!")
301
+ else:
302
+ print("\n❌ Deployment failed!")
303
+ print("\n🔧 Troubleshooting:")
304
+ print("1. Check that all required files are present")
305
+ print("2. Verify your Hugging Face credentials")
306
+ print("3. Ensure git is installed and configured")
307
+ print("4. Check the build logs in your Hugging Face Space")
308
+
309
+ if __name__ == "__main__":
310
+ main()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.104.1
2
+ uvicorn[standard]==0.24.0
3
+ pandas==2.1.3
4
+ numpy==1.25.2
5
+ scikit-learn==1.3.2
6
+ joblib==1.3.2
7
+ pydantic==2.5.0
8
+ python-multipart==0.0.6
train_model.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Standalone script to train the email classifier model
4
+ """
5
+
6
+ import pandas as pd
7
+ import numpy as np
8
+ from sklearn.feature_extraction.text import TfidfVectorizer
9
+ from sklearn.naive_bayes import MultinomialNB
10
+ from sklearn.pipeline import Pipeline
11
+ from sklearn.model_selection import train_test_split, cross_val_score
12
+ from sklearn.metrics import classification_report, accuracy_score, confusion_matrix
13
+ import joblib
14
+ import re
15
+ import os
16
+ from datetime import datetime
17
+
18
+ def preprocess_text(text: str) -> str:
19
+ """Preprocess email text"""
20
+ text = text.lower()
21
+ text = re.sub(r'\s+', ' ', text)
22
+ text = re.sub(r'[^\w\s,.\-!?]', ' ', text)
23
+ return text.strip()
24
+
25
+ def load_data(file_path: str):
26
+ """Load and preprocess the dataset"""
27
+ print(f"Loading dataset from {file_path}...")
28
+
29
+ if not os.path.exists(file_path):
30
+ print(f"Error: Dataset file {file_path} not found!")
31
+ return None, None
32
+
33
+ df = pd.read_csv(file_path)
34
+ print(f"Dataset loaded: {len(df)} samples")
35
+ print(f"Columns: {list(df.columns)}")
36
+
37
+ # Basic data info
38
+ print(f"\nLabel distribution:")
39
+ print(df['label'].value_counts())
40
+
41
+ # Preprocess messages
42
+ df['processed_message'] = df['message'].apply(preprocess_text)
43
+
44
+ return df['processed_message'], df['label']
45
+
46
+ def train_model(X, y):
47
+ """Train the Naive Bayes model"""
48
+ print("\nSplitting data...")
49
+ X_train, X_test, y_train, y_test = train_test_split(
50
+ X, y, test_size=0.2, random_state=42, stratify=y
51
+ )
52
+
53
+ print(f"Training set: {len(X_train)} samples")
54
+ print(f"Test set: {len(X_test)} samples")
55
+
56
+ # Create pipeline
57
+ print("\nCreating model pipeline...")
58
+ pipeline = Pipeline([
59
+ ('tfidf', TfidfVectorizer(
60
+ max_features=1000,
61
+ ngram_range=(1, 2),
62
+ stop_words='english',
63
+ lowercase=True,
64
+ min_df=1,
65
+ max_df=0.95
66
+ )),
67
+ ('classifier', MultinomialNB(alpha=1.0))
68
+ ])
69
+
70
+ # Train model
71
+ print("Training model...")
72
+ pipeline.fit(X_train, y_train)
73
+
74
+ # Cross-validation
75
+ print("Performing cross-validation...")
76
+ cv_scores = cross_val_score(pipeline, X_train, y_train, cv=5, scoring='accuracy')
77
+ print(f"Cross-validation scores: {cv_scores}")
78
+ print(f"Mean CV accuracy: {cv_scores.mean():.4f} (+/- {cv_scores.std() * 2:.4f})")
79
+
80
+ # Test set evaluation
81
+ print("\nEvaluating on test set...")
82
+ y_pred = pipeline.predict(X_test)
83
+ test_accuracy = accuracy_score(y_test, y_pred)
84
+
85
+ print(f"Test accuracy: {test_accuracy:.4f}")
86
+ print("\nClassification Report:")
87
+ print(classification_report(y_test, y_pred, target_names=['No Attachment', 'Has Attachment']))
88
+
89
+ print("\nConfusion Matrix:")
90
+ print(confusion_matrix(y_test, y_pred))
91
+
92
+ # Feature analysis
93
+ print("\nAnalyzing most important features...")
94
+ feature_names = pipeline.named_steps['tfidf'].get_feature_names_out()
95
+ feature_scores = pipeline.named_steps['classifier'].feature_log_prob_
96
+
97
+ # Top features for each class
98
+ for class_idx, class_name in enumerate(['No Attachment', 'Has Attachment']):
99
+ top_features_idx = np.argsort(feature_scores[class_idx])[-20:]
100
+ top_features = [feature_names[i] for i in top_features_idx]
101
+ print(f"\nTop 20 features for {class_name}:")
102
+ print(", ".join(reversed(top_features)))
103
+
104
+ return pipeline, test_accuracy
105
+
106
+ def save_model(pipeline, accuracy, output_path='email_classifier_model.pkl'):
107
+ """Save the trained model"""
108
+ print(f"\nSaving model to {output_path}...")
109
+
110
+ # Add metadata
111
+ model_info = {
112
+ 'pipeline': pipeline,
113
+ 'accuracy': accuracy,
114
+ 'feature_count': len(pipeline.named_steps['tfidf'].vocabulary_),
115
+ 'training_date': datetime.now().isoformat(),
116
+ 'model_type': 'Multinomial Naive Bayes',
117
+ 'preprocessing': 'TF-IDF with 1-2 grams'
118
+ }
119
+
120
+ joblib.dump(model_info, output_path)
121
+ print(f"Model saved successfully!")
122
+ print(f"Model info:")
123
+ print(f" - Accuracy: {accuracy:.4f}")
124
+ print(f" - Features: {model_info['feature_count']}")
125
+ print(f" - Training date: {model_info['training_date']}")
126
+
127
+ def test_model_predictions(pipeline):
128
+ """Test model with sample predictions"""
129
+ print("\n" + "="*50)
130
+ print("TESTING MODEL WITH SAMPLE PREDICTIONS")
131
+ print("="*50)
132
+
133
+ test_messages = [
134
+ "Hello, please find attached the document you requested.",
135
+ "Good morning, I'm sharing the report as discussed.",
136
+ "Hi team, attached is the presentation for tomorrow's meeting.",
137
+ "Dear all, kindly review the attached files.",
138
+ "Hello, how are you doing today?",
139
+ "I will send you the information later.",
140
+ "Please let me know if you need any clarification.",
141
+ "The meeting is scheduled for 3 PM tomorrow."
142
+ ]
143
+
144
+ for msg in test_messages:
145
+ processed_msg = preprocess_text(msg)
146
+ prediction = pipeline.predict([processed_msg])[0]
147
+ probabilities = pipeline.predict_proba([processed_msg])[0]
148
+ confidence = max(probabilities)
149
+
150
+ label = "Has Attachment" if prediction == 1 else "No Attachment"
151
+ print(f"\nMessage: '{msg}'")
152
+ print(f"Prediction: {label} (confidence: {confidence:.3f})")
153
+ print(f"Probabilities: No={probabilities[0]:.3f}, Yes={probabilities[1]:.3f}")
154
+
155
+ def main():
156
+ """Main training function"""
157
+ print("="*60)
158
+ print("EMAIL ATTACHMENT CLASSIFIER TRAINING")
159
+ print("="*60)
160
+
161
+ # Load data
162
+ dataset_path = 'Synthetic_Email_Dataset.csv'
163
+ X, y = load_data(dataset_path)
164
+
165
+ if X is None:
166
+ print("Failed to load dataset. Exiting...")
167
+ return
168
+
169
+ # Train model
170
+ pipeline, accuracy = train_model(X, y)
171
+
172
+ # Save model
173
+ save_model(pipeline, accuracy)
174
+
175
+ # Test predictions
176
+ test_model_predictions(pipeline)
177
+
178
+ print("\n" + "="*60)
179
+ print("TRAINING COMPLETED SUCCESSFULLY!")
180
+ print("="*60)
181
+ print(f"Final model accuracy: {accuracy:.4f}")
182
+ print("Model saved as 'email_classifier_model.pkl'")
183
+ print("You can now deploy the API using 'python app.py'")
184
+
185
+ if __name__ == "__main__":
186
+ main()