Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from gingerit.gingerit import GingerIt # Import GingerIt for grammar correction
|
4 |
import os
|
5 |
from datetime import datetime # Import datetime for date validation
|
6 |
|
7 |
-
# Initialize GingerIt parser
|
8 |
-
ginger_parser = GingerIt()
|
9 |
-
|
10 |
# Load Groq Cloud API key securely from environment variables
|
11 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
12 |
|
@@ -20,16 +16,20 @@ def fetch_public_data(name, dob, city):
|
|
20 |
|
21 |
return bio, linkedin_profile
|
22 |
|
23 |
-
# Helper function to call Groq Cloud LLM API to generate email
|
24 |
-
def
|
25 |
url = "https://api.groq.com/openai/v1/chat/completions" # Updated API URL for Groq Cloud
|
26 |
headers = {
|
27 |
"Authorization": f"Bearer {groq_api_key}", # Use the API key securely from environment
|
28 |
"Content-Type": "application/json",
|
29 |
}
|
30 |
|
31 |
-
# Updated prompt
|
32 |
-
prompt = f"
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Construct the data payload for the API request
|
35 |
data = {
|
@@ -52,11 +52,6 @@ def generate_email_from_groq(bio, company_name, role):
|
|
52 |
print(f"Error: {response.status_code}, {response.text}")
|
53 |
return "Error generating email. Please check your API key or try again later."
|
54 |
|
55 |
-
# Grammar and Tone Checker Function using GingerIt
|
56 |
-
def check_grammar(email_text):
|
57 |
-
corrected_text = ginger_parser.parse(email_text)["result"]
|
58 |
-
return corrected_text
|
59 |
-
|
60 |
# Function to validate the DOB format (DD-MM-YYYY)
|
61 |
def validate_dob(dob):
|
62 |
try:
|
@@ -77,16 +72,13 @@ def create_email(name, dob, city, company_name, role, email, phone):
|
|
77 |
bio, linkedin_profile = fetch_public_data(name, dob, city)
|
78 |
|
79 |
# Step 2: Generate the email using Groq Cloud LLM
|
80 |
-
generated_email =
|
81 |
|
82 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
83 |
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile}"
|
84 |
|
85 |
-
# Step 4: Run grammar and tone check using GingerIt
|
86 |
-
polished_email = check_grammar(generated_email + signature)
|
87 |
-
|
88 |
# Return the final polished email with the signature
|
89 |
-
return
|
90 |
|
91 |
# Define interface with Gradio
|
92 |
def gradio_ui():
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
import os
|
4 |
from datetime import datetime # Import datetime for date validation
|
5 |
|
|
|
|
|
|
|
6 |
# Load Groq Cloud API key securely from environment variables
|
7 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
8 |
|
|
|
16 |
|
17 |
return bio, linkedin_profile
|
18 |
|
19 |
+
# Helper function to call Groq Cloud LLM API to generate and correct the email
|
20 |
+
def generate_and_correct_email(bio, company_name, role):
|
21 |
url = "https://api.groq.com/openai/v1/chat/completions" # Updated API URL for Groq Cloud
|
22 |
headers = {
|
23 |
"Authorization": f"Bearer {groq_api_key}", # Use the API key securely from environment
|
24 |
"Content-Type": "application/json",
|
25 |
}
|
26 |
|
27 |
+
# Updated prompt to ask the model to generate AND correct the email
|
28 |
+
prompt = f"""
|
29 |
+
Write a professional email applying for a {role} position at {company_name}. Use this bio: {bio}.
|
30 |
+
The email should include an introduction, relevant experience, skills, and a closing.
|
31 |
+
Ensure that the email is grammatically correct and formal.
|
32 |
+
"""
|
33 |
|
34 |
# Construct the data payload for the API request
|
35 |
data = {
|
|
|
52 |
print(f"Error: {response.status_code}, {response.text}")
|
53 |
return "Error generating email. Please check your API key or try again later."
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
# Function to validate the DOB format (DD-MM-YYYY)
|
56 |
def validate_dob(dob):
|
57 |
try:
|
|
|
72 |
bio, linkedin_profile = fetch_public_data(name, dob, city)
|
73 |
|
74 |
# Step 2: Generate the email using Groq Cloud LLM
|
75 |
+
generated_email = generate_and_correct_email(bio, company_name, role)
|
76 |
|
77 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
78 |
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile}"
|
79 |
|
|
|
|
|
|
|
80 |
# Return the final polished email with the signature
|
81 |
+
return generated_email + signature
|
82 |
|
83 |
# Define interface with Gradio
|
84 |
def gradio_ui():
|