siddhartharya commited on
Commit
cdbe688
·
verified ·
1 Parent(s): 2e10399

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
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 Groq Cloud API key securely from environment variables
 
7
  groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
8
 
9
- # Scraping function to fetch user public data (for demo purposes, we will simulate this)
10
- def fetch_public_data(name, dob, city):
11
- # Simulate fetched bio data for demonstration purposes
12
- 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."
 
 
 
 
 
 
 
13
 
14
- # Since we're asking the user to input their LinkedIn URL, we'll no longer scrape LinkedIn.
15
- linkedin_profile = None
 
 
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):
@@ -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, linkedin_profile):
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 public data based on user info (no need to scrape LinkedIn anymore)
72
- bio, _ = fetch_public_data(name, dob, city) # We'll use the provided LinkedIn URL
 
 
 
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, linkedin_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.",