suzall commited on
Commit
86723f0
·
verified ·
1 Parent(s): 10fca88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -123
app.py CHANGED
@@ -1,123 +1,92 @@
1
-
2
- import streamlit as st
3
- import yagmail
4
- from datasets import load_dataset, Dataset, concatenate_datasets
5
- import pandas as pd
6
- import os
7
-
8
-
9
-
10
-
11
- # Send Email
12
- def send_email(hr_email, subject, body, resume_path, sender_email, sender_password):
13
- yag = yagmail.SMTP(user=sender_email, password=sender_password)
14
- yag.send(to=hr_email, subject=subject, contents=body, attachments=resume_path)
15
-
16
- # Load existing dataset or create a new one
17
- def load_hf_dataset(repo_id):
18
- try:
19
- dataset = load_dataset(repo_id, split="train")
20
- return dataset
21
- except Exception:
22
- return None
23
-
24
- # Save data to Hugging Face dataset
25
- def save_to_hf_dataset(repo_id, new_data, existing_dataset=None):
26
- try:
27
- # Convert new data into a Dataset
28
- new_dataset = Dataset.from_dict(new_data)
29
-
30
- # If existing dataset, concatenate with the new one
31
- if existing_dataset:
32
- updated_dataset = concatenate_datasets([existing_dataset, new_dataset])
33
- else:
34
- updated_dataset = new_dataset
35
-
36
- # Get Hugging Face token from environment variable
37
- hf_token = os.getenv('HF_TOKEN')
38
- if not hf_token:
39
- raise ValueError("Hugging Face token is missing or invalid")
40
-
41
- # Push the dataset to Hugging Face Hub with token authentication
42
- updated_dataset.push_to_hub(repo_id)
43
- return True
44
- except Exception as e:
45
- st.error(f"Error saving to dataset: {e}")
46
- return False
47
-
48
- # Streamlit Frontend
49
- def main():
50
- st.title("Email Sender")
51
-
52
- # Input fields
53
- hr_email = st.text_input("Enter HR's Email", placeholder="hr@example.com")
54
- job_profile = st.text_input("Enter Job Profile", placeholder="e.g., Python Developer")
55
- company_name = st.text_input("Enter Company Name", placeholder="e.g., Accenture")
56
- city=st.text_input("Enter City", placeholder="e.g. Pune")
57
- access_id=st.text_input("Enter Access ID")
58
-
59
- # Dataset repo ID
60
- hf_repo_id = "suzall/mails"
61
-
62
- # Submit button
63
- if st.button("Send Email"):
64
- if not hr_email:
65
- st.error("HR email is required!")
66
- return
67
- if not job_profile:
68
- st.error("Job profile is required!")
69
- return
70
- if not company_name:
71
- st.error("Company name is required!")
72
- return
73
- if not city:
74
- st.error("City is required!")
75
- return
76
- if not access_id:
77
- st.error("Access ID is required!")
78
- return
79
-
80
- # Backend data
81
- resume_path = "resume.pdf"
82
-
83
- # Generate email
84
- email_body = f"""
85
- Hi,
86
-
87
- I'm Sujal Tamrakar, and I'm interested in the {job_profile} position at {company_name}. I have a background in B.Tech(IT). I'm excited about the opportunity to contribute to your team. Please find my resume attached.
88
-
89
- Thank you,
90
- Sujal Tamrakar
91
- +91-7067599678
92
- """
93
-
94
- # Email configuration
95
- sender_email = "sanskarsujaltamrakar2903@gmail.com"
96
- if access_id=='2003':
97
- sender_password = "livb cebd xetz sgoh"
98
-
99
- # Send email
100
- try:
101
- send_email(hr_email, f"Job Application for {job_profile}", email_body, resume_path, sender_email, sender_password)
102
- st.success("Email sent successfully!")
103
-
104
- # Prepare data to store
105
- new_data = {
106
- "hr_email": [hr_email],
107
- "job_profile": [job_profile],
108
- "company_name": [company_name],
109
- "company_city": [city]
110
- }
111
-
112
- # Load existing dataset
113
- existing_dataset = load_hf_dataset(hf_repo_id)
114
-
115
- # Save data to Hugging Face dataset
116
- if save_to_hf_dataset(hf_repo_id, new_data, existing_dataset):
117
- st.success("Data saved to Hugging Face dataset successfully!")
118
-
119
- except Exception as e:
120
- st.error(f"Error sending email or saving data: {e}")
121
-
122
- if __name__== "__main__":
123
- main()
 
1
+ import gradio as gr
2
+ import yagmail
3
+ from datasets import load_dataset, Dataset, concatenate_datasets
4
+ import pandas as pd
5
+ import os
6
+ from dotenv import load_dotenv
7
+ load_dotenv() # Load environment variables from.env file
8
+
9
+ # Email Sending Function
10
+ def send_email(hr_email, subject, body, resume_path, sender_email, sender_password):
11
+ yag = yagmail.SMTP(user=sender_email, password=sender_password)
12
+ yag.send(to=hr_email, subject=subject, contents=body, attachments=resume_path)
13
+
14
+ # Load Existing Dataset or Create a New One
15
+ def load_hf_dataset(repo_id):
16
+ try:
17
+ dataset = load_dataset(repo_id, split="train")
18
+ return dataset
19
+ except Exception:
20
+ return None
21
+
22
+ # Save Data to Hugging Face Dataset
23
+ def save_to_hf_dataset(repo_id, new_data, existing_dataset=None):
24
+ try:
25
+ new_dataset = Dataset.from_dict(new_data)
26
+ if existing_dataset:
27
+ updated_dataset = concatenate_datasets([existing_dataset, new_dataset])
28
+ else:
29
+ updated_dataset = new_dataset
30
+ hf_token = os.getenv('HF_TOKEN')
31
+ if not hf_token:
32
+ raise ValueError("Hugging Face token is missing or invalid")
33
+ updated_dataset.push_to_hub(repo_id)
34
+ return True
35
+ except Exception as e:
36
+ print(f"Error saving to dataset: {e}")
37
+ return False
38
+
39
+ # Main Function for Gradio Interface
40
+ def process_form(hr_email, job_profile, company_name, city, access_id):
41
+ resume_path = "resume/resume.pdf"
42
+ email_body = f"""
43
+ # Your email body template, keep it brief for this example
44
+ Dear Hiring Manager,
45
+
46
+ I'm excited to apply for the {job_profile} role at {company_name}.
47
+
48
+ Best Regards,
49
+ [Your Name]
50
+ """
51
+
52
+ sender_email = os.getenv('SENDER_EMAIL')
53
+ sender_password = os.getenv('SENDER_PASSWORD') if access_id=='2003' else None
54
+
55
+ if sender_password:
56
+ try:
57
+ send_email(hr_email, f"Application for {job_profile} at {company_name}", email_body, resume_path, sender_email, sender_password)
58
+ print("Email sent successfully!")
59
+
60
+ new_data = {
61
+ "hr_email": [hr_email],
62
+ "job_profile": [job_profile],
63
+ "company_name": [company_name],
64
+ "company_city": [city]
65
+ }
66
+
67
+ existing_dataset = load_hf_dataset("suzall/mails")
68
+ if save_to_hf_dataset("suzall/mails", new_data, existing_dataset):
69
+ print("Data saved to Hugging Face dataset successfully!")
70
+ return "Email Sent and Data Saved Successfully!"
71
+ except Exception as e:
72
+ return f"Error: {e}"
73
+ else:
74
+ return "Invalid Access ID for sending email."
75
+
76
+ # Gradio Interface
77
+ demo = gr.Interface(
78
+ fn=process_form,
79
+ inputs=[
80
+ gr.Textbox(label="HR's Email", placeholder="hr@example.com"),
81
+ gr.Textbox(label="Job Profile", placeholder="e.g., Python Developer"),
82
+ gr.Textbox(label="Company Name", placeholder="e.g., Accenture"),
83
+ gr.Textbox(label="City", placeholder="e.g., Pune"),
84
+ gr.Textbox(label="Access ID", placeholder="Enter Access ID")
85
+ ],
86
+ outputs=gr.Textbox(label="Output"),
87
+ title="Email Sender",
88
+ description="Send an email to HR with your application details.",
89
+ )
90
+
91
+ if __name__ == "__main__":
92
+ demo.launch()