Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
|
|
4 |
|
5 |
# Load API keys securely from environment variables
|
6 |
proxycurl_api_key = os.getenv("PROXYCURL_API_KEY") # Proxycurl API key
|
@@ -25,6 +26,10 @@ class EmailAgent:
|
|
25 |
# Reason: Decide what information is needed
|
26 |
def reason_about_data(self):
|
27 |
print("Reasoning: I need LinkedIn data, company info, and role description.")
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Action: Fetch LinkedIn data via Proxycurl
|
30 |
def fetch_linkedin_data(self):
|
@@ -69,16 +74,47 @@ class EmailAgent:
|
|
69 |
else:
|
70 |
print(f"Error: Unable to fetch company info for {self.company_name}. Using default info.")
|
71 |
self.company_info = "A leading company in its field, offering innovative solutions."
|
72 |
-
|
73 |
-
# Action:
|
74 |
-
def
|
75 |
-
print(f"Action:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
self.role_description = f"The role of {self.role} at {self.company_name} involves mentoring AI and technology students to develop their skills and progress their careers."
|
77 |
|
78 |
# Reflection: Check if the data is sufficient to generate an email
|
79 |
def reflect_on_data(self):
|
80 |
print("Reflection: Do I have enough data to generate the email?")
|
81 |
# Allow the email to be generated with default values if data is missing
|
|
|
|
|
82 |
return True
|
83 |
|
84 |
# Action: Generate the email using Groq Cloud LLM
|
@@ -128,7 +164,9 @@ class EmailAgent:
|
|
128 |
self.reason_about_data() # Reason
|
129 |
self.fetch_linkedin_data() # Action
|
130 |
self.fetch_company_info() # Action
|
131 |
-
|
|
|
|
|
132 |
if self.reflect_on_data(): # Reflection
|
133 |
return self.generate_email() # Final Action
|
134 |
else:
|
@@ -169,3 +207,5 @@ def gradio_ui():
|
|
169 |
# Start the Gradio app when running the script
|
170 |
if __name__ == "__main__":
|
171 |
gradio_ui()
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
+
from bs4 import BeautifulSoup # Add BeautifulSoup for scraping
|
5 |
|
6 |
# Load API keys securely from environment variables
|
7 |
proxycurl_api_key = os.getenv("PROXYCURL_API_KEY") # Proxycurl API key
|
|
|
26 |
# Reason: Decide what information is needed
|
27 |
def reason_about_data(self):
|
28 |
print("Reasoning: I need LinkedIn data, company info, and role description.")
|
29 |
+
if not self.linkedin_url:
|
30 |
+
print("Warning: LinkedIn URL missing. Will proceed with default bio.")
|
31 |
+
if not self.company_name:
|
32 |
+
print("Warning: Company name missing. Will proceed with default company info.")
|
33 |
|
34 |
# Action: Fetch LinkedIn data via Proxycurl
|
35 |
def fetch_linkedin_data(self):
|
|
|
74 |
else:
|
75 |
print(f"Error: Unable to fetch company info for {self.company_name}. Using default info.")
|
76 |
self.company_info = "A leading company in its field, offering innovative solutions."
|
77 |
+
|
78 |
+
# Action: Scrape the company's website for role-specific information
|
79 |
+
def scrape_role_from_website(self):
|
80 |
+
print(f"Action: Scraping role description from the company's website for {self.role}.")
|
81 |
+
if not self.company_name:
|
82 |
+
print("Error: No company name or URL provided for scraping.")
|
83 |
+
return False
|
84 |
+
|
85 |
+
# Attempt to scrape the company's website
|
86 |
+
try:
|
87 |
+
response = requests.get(f"https://{self.company_name}.com/careers")
|
88 |
+
if response.status_code == 200:
|
89 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
90 |
+
# Look for any sections that might contain role descriptions
|
91 |
+
role_descriptions = soup.find_all(string=lambda text: self.role.lower() in text.lower())
|
92 |
+
if role_descriptions:
|
93 |
+
# If we find relevant role descriptions, use the first match
|
94 |
+
self.role_description = role_descriptions[0]
|
95 |
+
print(f"Found role description on company's website: {self.role_description}")
|
96 |
+
return True
|
97 |
+
else:
|
98 |
+
print(f"No specific role description found on the website for {self.role}.")
|
99 |
+
return False
|
100 |
+
else:
|
101 |
+
print(f"Error: Unable to reach company's website at {self.company_name}.com.")
|
102 |
+
return False
|
103 |
+
except Exception as e:
|
104 |
+
print(f"Error during scraping: {e}")
|
105 |
+
return False
|
106 |
+
|
107 |
+
# Action: Use default logic to infer role description if scraping fails
|
108 |
+
def use_default_role_description(self):
|
109 |
+
print(f"Action: Using default logic for the role of {self.role}.")
|
110 |
self.role_description = f"The role of {self.role} at {self.company_name} involves mentoring AI and technology students to develop their skills and progress their careers."
|
111 |
|
112 |
# Reflection: Check if the data is sufficient to generate an email
|
113 |
def reflect_on_data(self):
|
114 |
print("Reflection: Do I have enough data to generate the email?")
|
115 |
# Allow the email to be generated with default values if data is missing
|
116 |
+
if not self.bio or not self.skills or not self.company_info:
|
117 |
+
print("Warning: Some critical information is missing. Proceeding with default values.")
|
118 |
return True
|
119 |
|
120 |
# Action: Generate the email using Groq Cloud LLM
|
|
|
164 |
self.reason_about_data() # Reason
|
165 |
self.fetch_linkedin_data() # Action
|
166 |
self.fetch_company_info() # Action
|
167 |
+
# Try to scrape the company's website for role-specific information
|
168 |
+
if not self.scrape_role_from_website():
|
169 |
+
self.use_default_role_description() # Use default logic if scraping fails
|
170 |
if self.reflect_on_data(): # Reflection
|
171 |
return self.generate_email() # Final Action
|
172 |
else:
|
|
|
207 |
# Start the Gradio app when running the script
|
208 |
if __name__ == "__main__":
|
209 |
gradio_ui()
|
210 |
+
|
211 |
+
|