Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
import requests
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Load API keys securely from environment variables
|
|
@@ -23,15 +23,57 @@ class EmailAgent:
|
|
| 23 |
self.company_info = None
|
| 24 |
self.role_description = None
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
def
|
| 28 |
-
print("Reasoning:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Action: Fetch LinkedIn data via Proxycurl (acting based on reasoning)
|
| 37 |
def fetch_linkedin_data(self):
|
|
@@ -79,13 +121,6 @@ class EmailAgent:
|
|
| 79 |
print(f"Error: Unable to fetch company info via Firecrawl. Using default info.")
|
| 80 |
self.company_info = "A leading company in its field."
|
| 81 |
|
| 82 |
-
# Reflection: Check if we have enough data to generate the email
|
| 83 |
-
def reflect_on_data(self):
|
| 84 |
-
print("Reflection: Do we have enough data?")
|
| 85 |
-
if not self.bio or not self.skills or not self.company_info:
|
| 86 |
-
print("Warning: Some critical information is missing. Proceeding with default values.")
|
| 87 |
-
return True
|
| 88 |
-
|
| 89 |
# Final Action: Generate the email using Groq Cloud LLM based on gathered data
|
| 90 |
def generate_email(self):
|
| 91 |
print("Action: Generating the email with the gathered information.")
|
|
@@ -133,14 +168,13 @@ class EmailAgent:
|
|
| 133 |
|
| 134 |
# Main loop following ReAct pattern
|
| 135 |
def run(self):
|
| 136 |
-
self.
|
|
|
|
|
|
|
| 137 |
self.fetch_linkedin_data() # Fetch LinkedIn data
|
| 138 |
self.fetch_company_info_with_firecrawl() # Fetch company data using Firecrawl
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
return self.generate_email() # Final action: generate email
|
| 142 |
-
else:
|
| 143 |
-
return "Error: Not enough data to generate the email."
|
| 144 |
|
| 145 |
# Define the Gradio interface and the main app logic
|
| 146 |
def gradio_ui():
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Load API keys securely from environment variables
|
|
|
|
| 23 |
self.company_info = None
|
| 24 |
self.role_description = None
|
| 25 |
|
| 26 |
+
# Use the LLM to reason and reflect on the provided data
|
| 27 |
+
def reason_with_llm(self):
|
| 28 |
+
print("Reasoning: Using LLM to reason about available data...")
|
| 29 |
+
|
| 30 |
+
# LLM reasoning prompt that evaluates the current data and reflects on next actions
|
| 31 |
+
reasoning_prompt = f"""
|
| 32 |
+
You are a reasoning agent tasked with generating a job application email. Here's what we have:
|
| 33 |
+
|
| 34 |
+
1. Candidate's LinkedIn profile URL: {self.linkedin_url}
|
| 35 |
+
2. Company Name: {self.company_name}
|
| 36 |
+
3. Role: {self.role}
|
| 37 |
+
4. Word Limit: {self.word_limit}
|
| 38 |
+
5. Candidate's Name: {self.user_name}
|
| 39 |
+
6. Candidate's Email: {self.email}
|
| 40 |
+
7. Candidate's Phone: {self.phone}
|
| 41 |
+
8. Candidate's LinkedIn: {self.linkedin}
|
| 42 |
+
|
| 43 |
+
Candidate's Bio: {self.bio}
|
| 44 |
+
Candidate's Skills: {', '.join(self.skills)}
|
| 45 |
+
Candidate's Experiences: {', '.join([exp['title'] for exp in self.experiences])}
|
| 46 |
+
|
| 47 |
+
Company Information: {self.company_info}
|
| 48 |
+
Role Description: {self.role_description}
|
| 49 |
+
|
| 50 |
+
Evaluate the completeness of the data. If some key data is missing, determine whether we should:
|
| 51 |
+
- Scrape for more data (e.g., company info, role descriptions).
|
| 52 |
+
- Proceed with the available information and generate the email using default logic.
|
| 53 |
+
|
| 54 |
+
Reflect on whether we need more data or if the current information is sufficient to proceed.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
# Send this reasoning prompt to the LLM
|
| 58 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 59 |
+
headers = {
|
| 60 |
+
"Authorization": f"Bearer {groq_api_key}",
|
| 61 |
+
"Content-Type": "application/json",
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
data = {
|
| 65 |
+
"messages": [{"role": "user", "content": reasoning_prompt}],
|
| 66 |
+
"model": "llama3-8b-8192"
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
response = requests.post(url, headers=headers, json=data)
|
| 70 |
+
if response.status_code == 200:
|
| 71 |
+
reasoning_output = response.json()["choices"][0]["message"]["content"].strip()
|
| 72 |
+
print("LLM Reasoning Output:", reasoning_output)
|
| 73 |
+
return reasoning_output
|
| 74 |
+
else:
|
| 75 |
+
print(f"Error: {response.status_code}, {response.text}")
|
| 76 |
+
return "Error: Unable to complete reasoning."
|
| 77 |
|
| 78 |
# Action: Fetch LinkedIn data via Proxycurl (acting based on reasoning)
|
| 79 |
def fetch_linkedin_data(self):
|
|
|
|
| 121 |
print(f"Error: Unable to fetch company info via Firecrawl. Using default info.")
|
| 122 |
self.company_info = "A leading company in its field."
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
# Final Action: Generate the email using Groq Cloud LLM based on gathered data
|
| 125 |
def generate_email(self):
|
| 126 |
print("Action: Generating the email with the gathered information.")
|
|
|
|
| 168 |
|
| 169 |
# Main loop following ReAct pattern
|
| 170 |
def run(self):
|
| 171 |
+
reasoning_output = self.reason_with_llm() # LLM performs reasoning and reflection
|
| 172 |
+
print("LLM Reflection:", reasoning_output)
|
| 173 |
+
|
| 174 |
self.fetch_linkedin_data() # Fetch LinkedIn data
|
| 175 |
self.fetch_company_info_with_firecrawl() # Fetch company data using Firecrawl
|
| 176 |
+
|
| 177 |
+
return self.generate_email() # Final action: generate email
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
# Define the Gradio interface and the main app logic
|
| 180 |
def gradio_ui():
|