satyamr196 commited on
Commit
6d12745
·
1 Parent(s): fdc104d

Added email notification whenever transcription for any new model is starts

Browse files
Files changed (3) hide show
  1. ASR_Server.py +16 -3
  2. requirements.txt +2 -1
  3. utils/send_email.py +52 -0
ASR_Server.py CHANGED
@@ -6,10 +6,13 @@ import os
6
  import re
7
  import threading
8
  from dotenv import load_dotenv
 
 
9
  from utils.load_csv import upload_csv, download_csv
10
  from utils.generate_results import generateResults
11
  from utils.generate_box_plot import box_plot_data
12
  from utils.model_validity import is_valid_asr_model
 
13
 
14
  # Set the cache directory for Hugging Face datasets
15
  os.environ["HF_HOME"] = "/tmp/huggingface"
@@ -19,6 +22,7 @@ import timeit
19
  cpu_score = timeit.timeit("sum(range(1000000))", number=5)
20
  print(f"🧠 CPU benchmark score: {cpu_score:.2f}")
21
 
 
22
  job_status = {
23
  "running": False,
24
  "model": None,
@@ -62,8 +66,17 @@ def generateTranscript(ASR_model):
62
  df_transcript = download_csv(csv_transcript)
63
  if(df_transcript is None):
64
  print(f"CSV not found in the dataset repo. Proceeding to generate transcript.")
 
 
 
 
 
 
 
 
 
65
  else:
66
- print(f"Transcript already exists for model {ASR_model}. Skipping transcription.")
67
  job_status["running"] = False
68
  job_status["message"] = "Transcription Already existss"
69
  return
@@ -161,7 +174,7 @@ def home():
161
  return jsonify(
162
  {
163
  "message": "Welcome to the ASR Server! Please use the App link to access ASR-FairBench application.",
164
- "App link": "https://github.com/SatyamR196/ASR-FairBench"
165
  }
166
  )
167
 
@@ -223,7 +236,7 @@ def api():
223
  # Check if `generateTranscript` is already running for this model
224
  if job_status["running"] :
225
  return jsonify({
226
- 'message': f'Transcription for {job_status["model"]} is in progress. Please wait for it to complete. Then submit your model again.',
227
  'status': job_status
228
  })
229
 
 
6
  import re
7
  import threading
8
  from dotenv import load_dotenv
9
+ from datetime import datetime
10
+ import pytz
11
  from utils.load_csv import upload_csv, download_csv
12
  from utils.generate_results import generateResults
13
  from utils.generate_box_plot import box_plot_data
14
  from utils.model_validity import is_valid_asr_model
15
+ from utils.send_email import send_email
16
 
17
  # Set the cache directory for Hugging Face datasets
18
  os.environ["HF_HOME"] = "/tmp/huggingface"
 
22
  cpu_score = timeit.timeit("sum(range(1000000))", number=5)
23
  print(f"🧠 CPU benchmark score: {cpu_score:.2f}")
24
 
25
+
26
  job_status = {
27
  "running": False,
28
  "model": None,
 
66
  df_transcript = download_csv(csv_transcript)
67
  if(df_transcript is None):
68
  print(f"CSV not found in the dataset repo. Proceeding to generate transcript.")
69
+ # Get current IST time
70
+ ist = pytz.timezone("Asia/Kolkata")
71
+ current_time = datetime.now(ist).strftime("%H:%M:%S %d %b %Y")
72
+ send_email(
73
+ to_email="[email protected]",
74
+ subject=f"Audit Started for ASR model {ASR_model}",
75
+ message_body=f"Audit started at {current_time} for ASR model {ASR_model}.",
76
+ bcc_emails=["[email protected]"]
77
+ )
78
  else:
79
+ print(f"Transcript already exists for previously submitted model. Skipping transcription.")
80
  job_status["running"] = False
81
  job_status["message"] = "Transcription Already existss"
82
  return
 
174
  return jsonify(
175
  {
176
  "message": "Welcome to the ASR Server! Please use the App link to access ASR-FairBench application.",
177
+ "App link": "https://huggingface.co/spaces/satyamr196/ASR-FairBench"
178
  }
179
  )
180
 
 
236
  # Check if `generateTranscript` is already running for this model
237
  if job_status["running"] :
238
  return jsonify({
239
+ 'message': f'Transcription for previously submitted ASR model is in progress. Please wait for it to complete. Then submit your model again.',
240
  'status': job_status
241
  })
242
 
requirements.txt CHANGED
@@ -16,4 +16,5 @@ flask-cors
16
  pandas
17
  tqdm
18
  dotenv
19
- huggingface_hub
 
 
16
  pandas
17
  tqdm
18
  dotenv
19
+ huggingface_hub
20
+ pytz
utils/send_email.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import smtplib
3
+ from email.mime.text import MIMEText
4
+ from dotenv import load_dotenv
5
+
6
+ # Load variables from .env if present
7
+ load_dotenv()
8
+
9
+ def send_email(to_email, subject, message_body, cc_emails=None, bcc_emails=None):
10
+ gmail_user = "[email protected]"
11
+ app_password = os.environ.get("APP_PASSWORD")
12
+
13
+ if not gmail_user or not app_password:
14
+ print("Environment variables GMAIL_USER or APP_PASSWORD not set.")
15
+ return False
16
+
17
+ try:
18
+ msg = MIMEText(message_body)
19
+ msg['Subject'] = subject
20
+ msg['From'] = gmail_user
21
+ msg['To'] = to_email
22
+
23
+ # Add CC if present
24
+ if cc_emails:
25
+ msg['Cc'] = ", ".join(cc_emails)
26
+
27
+ # Combine all recipients for sending
28
+ recipients = [to_email]
29
+ if cc_emails:
30
+ recipients += cc_emails
31
+ if bcc_emails:
32
+ recipients += bcc_emails
33
+
34
+ with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
35
+ smtp.login(gmail_user, app_password)
36
+ smtp.sendmail(gmail_user, recipients, msg.as_string())
37
+
38
+ print("Email sent successfully.")
39
+ return True
40
+
41
+ except Exception as e:
42
+ print(f"Error sending email: {e}")
43
+ return False
44
+
45
+ # Example usage
46
+ # send_email(
47
+ # to_email="[email protected]",
48
+ # subject="Auto email API TESTING : Email with CC and BCC",
49
+ # message_body="This message has been sent for testing CC and BCC support!",
50
+ # cc_emails=["[email protected]","[email protected]"],
51
+ # bcc_emails=["[email protected]"]
52
+ # )