siddhartharya commited on
Commit
e3f43f3
·
verified ·
1 Parent(s): 71ca416

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import requests
3
- from serpapi import GoogleSearch # Corrected SerpAPI import
4
  import os
5
  from datetime import datetime # Import datetime for date validation
6
 
@@ -8,24 +7,21 @@ from datetime import datetime # Import datetime for date validation
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):
 
1
  import gradio as gr
2
  import requests
 
3
  import os
4
  from datetime import datetime # Import datetime for date validation
5
 
 
7
  serpapi_key = os.getenv("SERPAPI_API_KEY") # Add your SerpAPI key to your environment variables
8
  groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
9
 
10
+ # Function to use SerpAPI to get the LinkedIn URL via HTTP requests
11
  def get_linkedin_profile_via_serpapi(name, city):
12
  query = f"{name} LinkedIn {city}"
13
+ url = f"https://serpapi.com/search.json?engine=google&q={query}&hl=en&gl=us&api_key={serpapi_key}"
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ response = requests.get(url)
16
+ if response.status_code == 200:
17
+ results = response.json()
18
+ # Look for LinkedIn profile in search results
19
+ for result in results.get("organic_results", []):
20
+ if "linkedin.com" in result.get("link", ""):
21
+ return result["link"]
22
+ return "LinkedIn profile not found"
23
+ else:
24
+ return "Error: Unable to fetch results from SerpAPI"
25
 
26
  # Helper function to call Groq Cloud LLM API to generate and correct the email
27
  def generate_and_correct_email(bio, company_name, role):