Update app.py
Browse files
app.py
CHANGED
|
@@ -1,123 +1,92 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
import
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
return
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
if
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
return
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|