Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import requests
|
|
3 |
import language_tool_python
|
4 |
from bs4 import BeautifulSoup
|
5 |
import os
|
|
|
6 |
|
7 |
# Load Groq Cloud API key from Hugging Face secrets
|
8 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
@@ -11,7 +12,11 @@ groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
|
11 |
def fetch_public_data(name, dob, city):
|
12 |
# Simulate fetched bio data for demonstration purposes
|
13 |
bio = f"{name} is a software engineer from {city} with over 10 years of experience. Known for work in AI, cloud computing, and leadership in various engineering teams."
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Helper function to call Groq Cloud LLM API to generate email
|
17 |
def generate_email_from_groq(bio, company_name, role):
|
@@ -41,16 +46,30 @@ def check_grammar(email_text):
|
|
41 |
corrected_text = language_tool_python.utils.correct(email_text, matches)
|
42 |
return corrected_text
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# Main function to create the email and allow for saving, editing, or copying
|
45 |
-
def create_email(name, dob, city, company_name, role, email, phone
|
|
|
|
|
|
|
|
|
46 |
# Step 1: Fetch public data based on user info
|
47 |
-
bio = fetch_public_data(name, dob, city)
|
48 |
|
49 |
# Step 2: Generate the email using Groq Cloud LLM
|
50 |
generated_email = generate_email_from_groq(bio, company_name, role)
|
51 |
|
52 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
53 |
-
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {
|
54 |
|
55 |
# Step 4: Run grammar and tone check
|
56 |
polished_email = check_grammar(generated_email + signature)
|
@@ -62,7 +81,7 @@ def create_email(name, dob, city, company_name, role, email, phone, linkedin):
|
|
62 |
def gradio_ui():
|
63 |
# Define inputs
|
64 |
name_input = gr.Textbox(label="Name", placeholder="Enter your name")
|
65 |
-
dob_input = gr.Textbox(label="Date of Birth", placeholder="Enter your date of birth (
|
66 |
city_input = gr.Textbox(label="City", placeholder="Enter your city of residence")
|
67 |
|
68 |
company_name_input = gr.Textbox(label="Company Name", placeholder="Enter the name of the company you are applying to")
|
@@ -70,7 +89,6 @@ def gradio_ui():
|
|
70 |
|
71 |
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address")
|
72 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
73 |
-
linkedin_input = gr.Textbox(label="LinkedIn Profile URL", placeholder="Enter your LinkedIn profile link")
|
74 |
|
75 |
# Define output for the generated email
|
76 |
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
@@ -78,7 +96,7 @@ def gradio_ui():
|
|
78 |
# Create the Gradio interface
|
79 |
demo = gr.Interface(
|
80 |
fn=create_email, # Function to call when the user submits
|
81 |
-
inputs=[name_input, dob_input, city_input, company_name_input, role_input, email_input, phone_input
|
82 |
outputs=[email_output],
|
83 |
title="Email Writing AI Agent",
|
84 |
description="Generate a professional email for a job application by providing your basic info.",
|
|
|
3 |
import language_tool_python
|
4 |
from bs4 import BeautifulSoup
|
5 |
import os
|
6 |
+
from datetime import datetime # Import datetime for date validation
|
7 |
|
8 |
# Load Groq Cloud API key from Hugging Face secrets
|
9 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
|
|
12 |
def fetch_public_data(name, dob, city):
|
13 |
# Simulate fetched bio data for demonstration purposes
|
14 |
bio = f"{name} is a software engineer from {city} with over 10 years of experience. Known for work in AI, cloud computing, and leadership in various engineering teams."
|
15 |
+
|
16 |
+
# Simulate LinkedIn profile scraping (replace this with actual scraping logic)
|
17 |
+
linkedin_profile = f"https://linkedin.com/in/{name.replace(' ', '').lower()}"
|
18 |
+
|
19 |
+
return bio, linkedin_profile
|
20 |
|
21 |
# Helper function to call Groq Cloud LLM API to generate email
|
22 |
def generate_email_from_groq(bio, company_name, role):
|
|
|
46 |
corrected_text = language_tool_python.utils.correct(email_text, matches)
|
47 |
return corrected_text
|
48 |
|
49 |
+
# Function to validate the DOB format (DD-MM-YYYY)
|
50 |
+
def validate_dob(dob):
|
51 |
+
try:
|
52 |
+
# Attempt to parse the DOB to the expected format
|
53 |
+
datetime.strptime(dob, "%d-%m-%Y")
|
54 |
+
return True
|
55 |
+
except ValueError:
|
56 |
+
# Return False if the format is invalid
|
57 |
+
return False
|
58 |
+
|
59 |
# Main function to create the email and allow for saving, editing, or copying
|
60 |
+
def create_email(name, dob, city, company_name, role, email, phone):
|
61 |
+
# Validate the DOB format (DD-MM-YYYY)
|
62 |
+
if not validate_dob(dob):
|
63 |
+
return "Invalid Date of Birth format. Please use DD-MM-YYYY."
|
64 |
+
|
65 |
# Step 1: Fetch public data based on user info
|
66 |
+
bio, linkedin_profile = fetch_public_data(name, dob, city)
|
67 |
|
68 |
# Step 2: Generate the email using Groq Cloud LLM
|
69 |
generated_email = generate_email_from_groq(bio, company_name, role)
|
70 |
|
71 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
72 |
+
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile}"
|
73 |
|
74 |
# Step 4: Run grammar and tone check
|
75 |
polished_email = check_grammar(generated_email + signature)
|
|
|
81 |
def gradio_ui():
|
82 |
# Define inputs
|
83 |
name_input = gr.Textbox(label="Name", placeholder="Enter your name")
|
84 |
+
dob_input = gr.Textbox(label="Date of Birth", placeholder="Enter your date of birth (DD-MM-YYYY)")
|
85 |
city_input = gr.Textbox(label="City", placeholder="Enter your city of residence")
|
86 |
|
87 |
company_name_input = gr.Textbox(label="Company Name", placeholder="Enter the name of the company you are applying to")
|
|
|
89 |
|
90 |
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address")
|
91 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
|
|
92 |
|
93 |
# Define output for the generated email
|
94 |
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
|
|
96 |
# Create the Gradio interface
|
97 |
demo = gr.Interface(
|
98 |
fn=create_email, # Function to call when the user submits
|
99 |
+
inputs=[name_input, dob_input, city_input, company_name_input, role_input, email_input, phone_input],
|
100 |
outputs=[email_output],
|
101 |
title="Email Writing AI Agent",
|
102 |
description="Generate a professional email for a job application by providing your basic info.",
|