Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
import os
|
4 |
from datetime import datetime # Import datetime for date validation
|
5 |
|
6 |
-
# Load
|
|
|
7 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
8 |
|
9 |
-
#
|
10 |
-
def
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
|
|
|
|
|
16 |
|
17 |
-
return
|
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):
|
@@ -63,13 +74,16 @@ def validate_dob(dob):
|
|
63 |
return False
|
64 |
|
65 |
# Main function to create the email and allow for saving, editing, or copying
|
66 |
-
def create_email(name, dob, city, company_name, role, email, phone
|
67 |
# Validate the DOB format (DD-MM-YYYY)
|
68 |
if not validate_dob(dob):
|
69 |
return "Invalid Date of Birth format. Please use DD-MM-YYYY."
|
70 |
|
71 |
-
# Step 1: Fetch
|
72 |
-
|
|
|
|
|
|
|
73 |
|
74 |
# Step 2: Generate the email using Groq Cloud LLM
|
75 |
generated_email = generate_and_correct_email(bio, company_name, role)
|
@@ -92,7 +106,6 @@ def gradio_ui():
|
|
92 |
|
93 |
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address")
|
94 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
95 |
-
linkedin_input = gr.Textbox(label="LinkedIn URL", placeholder="Enter your LinkedIn profile URL") # New input field for LinkedIn URL
|
96 |
|
97 |
# Define output for the generated email
|
98 |
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
@@ -100,7 +113,7 @@ def gradio_ui():
|
|
100 |
# Create the Gradio interface
|
101 |
demo = gr.Interface(
|
102 |
fn=create_email, # Function to call when the user submits
|
103 |
-
inputs=[name_input, dob_input, city_input, company_name_input, role_input, email_input, phone_input
|
104 |
outputs=[email_output],
|
105 |
title="Email Writing AI Agent",
|
106 |
description="Generate a professional email for a job application by providing your basic info.",
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
from serpapi import GoogleSearch # Import SerpAPI for searching
|
4 |
import os
|
5 |
from datetime import datetime # Import datetime for date validation
|
6 |
|
7 |
+
# Load API keys securely from environment variables
|
8 |
+
serpapi_key = os.getenv("SERPAPI_API_KEY") # Add your SerpAPI key to your environment variables
|
9 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
10 |
|
11 |
+
# Function to use SerpAPI to get the LinkedIn URL
|
12 |
+
def get_linkedin_profile_via_serpapi(name, city):
|
13 |
+
query = f"{name} LinkedIn {city}"
|
14 |
+
params = {
|
15 |
+
"q": query,
|
16 |
+
"hl": "en",
|
17 |
+
"gl": "us",
|
18 |
+
"api_key": serpapi_key,
|
19 |
+
}
|
20 |
+
search = GoogleSearch(params)
|
21 |
+
results = search.get_dict()
|
22 |
|
23 |
+
# Look for LinkedIn profile in search results
|
24 |
+
for result in results.get("organic_results", []):
|
25 |
+
if "linkedin.com" in result.get("link", ""):
|
26 |
+
return result["link"]
|
27 |
|
28 |
+
return "LinkedIn profile not found"
|
29 |
|
30 |
# Helper function to call Groq Cloud LLM API to generate and correct the email
|
31 |
def generate_and_correct_email(bio, company_name, role):
|
|
|
74 |
return False
|
75 |
|
76 |
# Main function to create the email and allow for saving, editing, or copying
|
77 |
+
def create_email(name, dob, city, company_name, role, email, phone):
|
78 |
# Validate the DOB format (DD-MM-YYYY)
|
79 |
if not validate_dob(dob):
|
80 |
return "Invalid Date of Birth format. Please use DD-MM-YYYY."
|
81 |
|
82 |
+
# Step 1: Fetch LinkedIn profile using SerpAPI
|
83 |
+
linkedin_profile = get_linkedin_profile_via_serpapi(name, city)
|
84 |
+
|
85 |
+
# Use a placeholder bio (you can extend this to fetch real bio data from LinkedIn)
|
86 |
+
bio = f"{name} is a professional in {city}."
|
87 |
|
88 |
# Step 2: Generate the email using Groq Cloud LLM
|
89 |
generated_email = generate_and_correct_email(bio, company_name, role)
|
|
|
106 |
|
107 |
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address")
|
108 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
|
|
109 |
|
110 |
# Define output for the generated email
|
111 |
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
|
|
113 |
# Create the Gradio interface
|
114 |
demo = gr.Interface(
|
115 |
fn=create_email, # Function to call when the user submits
|
116 |
+
inputs=[name_input, dob_input, city_input, company_name_input, role_input, email_input, phone_input],
|
117 |
outputs=[email_output],
|
118 |
title="Email Writing AI Agent",
|
119 |
description="Generate a professional email for a job application by providing your basic info.",
|