import gradio as gr import yagmail from datasets import load_dataset, Dataset, concatenate_datasets import pandas as pd import os from dotenv import load_dotenv load_dotenv() # Load environment variables from.env file # Email Sending Function def send_email(hr_email, subject, body, resume_path, sender_email, sender_password): yag = yagmail.SMTP(user=sender_email, password=sender_password) yag.send(to=hr_email, subject=subject, contents=body, attachments=resume_path) # Load Existing Dataset or Create a New One def load_hf_dataset(repo_id): try: dataset = load_dataset(repo_id, split="train") return dataset except Exception: return None # Save Data to Hugging Face Dataset def save_to_hf_dataset(repo_id, new_data, existing_dataset=None): try: new_dataset = Dataset.from_dict(new_data) if existing_dataset: updated_dataset = concatenate_datasets([existing_dataset, new_dataset]) else: updated_dataset = new_dataset hf_token = os.getenv('HF_TOKEN') if not hf_token: raise ValueError("Hugging Face token is missing or invalid") updated_dataset.push_to_hub(repo_id) return True except Exception as e: print(f"Error saving to dataset: {e}") return False # Main Function for Gradio Interface def process_form(hr_email, job_profile, company_name, city, access_id): resume_path = "SujalTamrakar.py.pdf" email_body = f""" Dear Hiring Manager, I'm excited to apply for the {job_profile} role at {company_name}. With a strong IT background (B.Tech, CGPA: 7.97) and experience in AI, Machine Learning, and Web Development, I'm confident in my ability to contribute to your team. Key Highlights: - AI Intern at VKAPS IT Solutions: Built & deployed AI projects using LangChain Python OpenAI - Data Science Trainee at Grow Tech: Utilized exploratory data analysis and SQL - Projects: Online Code Review Tool, Automatic Ticket Classification Tool (details on attached resume) Tech Skills: - Programming: Python, SQL - AI/ML: LangChain, LLMs, Pinecone, Cohere - Web Dev: Streamlit Attached: Resume (including full project details, education, and additional experience) Contact: - Email: sujal.tamrakar@outlook.com - Phone: +91-7067599678 - LinkedIn: linkedin.com/in/sujaltamrakar - GitHub: github.com/sujal03 Best Regards, Sujal Tamrakar """ sender_email = os.getenv('SENDER_EMAIL') sender_password = os.getenv('SENDER_PASSWORD') if access_id=='2003' else None if sender_password: try: send_email(hr_email, f"Application for {job_profile} at {company_name}", email_body, resume_path, sender_email, sender_password) print("Email sent successfully!") new_data = { "hr_email": [hr_email], "job_profile": [job_profile], "company_name": [company_name], "company_city": [city] } existing_dataset = load_hf_dataset("suzall/mails") if save_to_hf_dataset("suzall/mails", new_data, existing_dataset): print("Data saved to Hugging Face dataset successfully!") return "Email Sent and Data Saved Successfully!" except Exception as e: return f"Error: {e}" else: return "Invalid Access ID for sending email." # Gradio Interface demo = gr.Interface( fn=process_form, inputs=[ gr.Textbox(label="HR's Email", placeholder="hr@example.com"), gr.Textbox(label="Job Profile", placeholder="e.g., Python Developer"), gr.Textbox(label="Company Name", placeholder="e.g., Accenture"), gr.Textbox(label="City", placeholder="e.g., Pune"), gr.Textbox(label="Access ID", placeholder="Enter Access ID") ], outputs=gr.Textbox(label="Output"), title="Email Sender", description="Send an email to HR with your application details.", ) if __name__ == "__main__": demo.launch()