|
import gradio as gr |
|
import requests |
|
import language_tool_python |
|
from bs4 import BeautifulSoup |
|
import os |
|
|
|
|
|
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY") |
|
|
|
|
|
def fetch_public_data(name, dob, city): |
|
|
|
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." |
|
return bio |
|
|
|
|
|
def generate_email_from_groq(bio, company_name, role): |
|
url = "https://api.groq.cloud/generate" |
|
headers = { |
|
"Authorization": f"Bearer {groq_api_key}", |
|
"Content-Type": "application/json", |
|
} |
|
prompt = f"Write a professional email applying for a {role} position at {company_name}. Use this bio: {bio}. The email should include an introduction, relevant experience, skills, and a closing." |
|
data = { |
|
"model": "groq-model", |
|
"prompt": prompt, |
|
"max_tokens": 300 |
|
} |
|
|
|
response = requests.post(url, headers=headers, json=data) |
|
|
|
if response.status_code == 200: |
|
return response.json().get("choices")[0].get("text").strip() |
|
else: |
|
return "Error generating email. Please check your API key or try again later." |
|
|
|
|
|
def check_grammar(email_text): |
|
tool = language_tool_python.LanguageTool('en-US') |
|
matches = tool.check(email_text) |
|
corrected_text = language_tool_python.utils.correct(email_text, matches) |
|
return corrected_text |
|
|
|
|
|
def create_email(name, dob, city, company_name, role): |
|
|
|
bio = fetch_public_data(name, dob, city) |
|
|
|
|
|
generated_email = generate_email_from_groq(bio, company_name, role) |
|
|
|
|
|
polished_email = check_grammar(generated_email) |
|
|
|
|
|
return polished_email |
|
|
|
|
|
def gradio_ui(): |
|
|
|
name_input = gr.Textbox(label="Name", placeholder="Enter your name") |
|
dob_input = gr.Textbox(label="Date of Birth", placeholder="Enter your date of birth (YYYY-MM-DD)") |
|
city_input = gr.Textbox(label="City", placeholder="Enter your city of residence") |
|
|
|
company_name_input = gr.Textbox(label="Company Name", placeholder="Enter the name of the company you are applying to") |
|
role_input = gr.Textbox(label="Role", placeholder="Enter the role you are applying for") |
|
|
|
|
|
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10) |
|
|
|
|
|
demo = gr.Interface( |
|
fn=create_email, |
|
inputs=[name_input, dob_input, city_input, company_name_input, role_input], |
|
outputs=[email_output], |
|
title="Email Writing AI Agent", |
|
description="Generate a professional email for a job application by providing your basic info.", |
|
allow_flagging="never" |
|
) |
|
|
|
|
|
demo.launch() |
|
|
|
|
|
if __name__ == "__main__": |
|
gradio_ui() |
|
|