siddhartharya commited on
Commit
11d6883
·
verified ·
1 Parent(s): f7c45b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -4
app.py CHANGED
@@ -19,6 +19,7 @@ class AutonomousEmailAgent:
19
  self.company_info = None
20
  self.role_description = None
21
  self.attempts = 0 # Counter for iterations
 
22
 
23
  def fetch_linkedin_data(self):
24
  proxycurl_api_key = os.getenv("PROXYCURL_API_KEY")
@@ -100,7 +101,7 @@ class AutonomousEmailAgent:
100
  if choices and "message" in choices[0]:
101
  content = choices[0]["message"]["content"]
102
  print(f"Content: {content}")
103
- return self.format_email(content)
104
  else:
105
  print("Error: Unrecognized format in LLM response.")
106
  return "Error: Unrecognized response format."
@@ -111,6 +112,25 @@ class AutonomousEmailAgent:
111
  print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}")
112
  return "Error: Unable to generate response."
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  def format_email(self, llm_response):
115
  # Clean and format the email
116
  lines = [line.strip() for line in llm_response.split("\n") if line.strip()]
@@ -144,6 +164,21 @@ class AutonomousEmailAgent:
144
 
145
  return f"{formatted_email}{closing_section}\n{signature}"
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  # Gradio UI setup remains unchanged
148
  def gradio_ui():
149
  name_input = gr.Textbox(label="Your Name", placeholder="Enter your name")
@@ -165,10 +200,8 @@ def gradio_ui():
165
  inputs=[name_input, company_input, role_input, email_input, phone_input, linkedin_input, word_limit_slider],
166
  outputs=[email_output],
167
  title="Email Writing AI Agent with ReAct",
168
- description="Generate a professional email for a job application using LinkedIn data, company info, and role description.",
169
- allow_flagging="never"
170
  )
171
-
172
  demo.launch()
173
 
174
  if __name__ == "__main__":
 
19
  self.company_info = None
20
  self.role_description = None
21
  self.attempts = 0 # Counter for iterations
22
+ self.max_attempts = 5 # Set maximum number of iterations
23
 
24
  def fetch_linkedin_data(self):
25
  proxycurl_api_key = os.getenv("PROXYCURL_API_KEY")
 
101
  if choices and "message" in choices[0]:
102
  content = choices[0]["message"]["content"]
103
  print(f"Content: {content}")
104
+ return self.act_on_llm_instructions(content)
105
  else:
106
  print("Error: Unrecognized format in LLM response.")
107
  return "Error: Unrecognized response format."
 
112
  print(f"Error: Unable to connect to Groq Cloud LLM. Status Code: {response.status_code}")
113
  return "Error: Unable to generate response."
114
 
115
+ def act_on_llm_instructions(self, llm_response):
116
+ if self.attempts >= self.max_attempts:
117
+ print("Max attempts reached. Proceeding with fallback option.")
118
+ return self.generate_fallback_email()
119
+
120
+ print(f"LLM Instruction: {llm_response}")
121
+ if "scrape" in llm_response.lower():
122
+ self.attempts += 1
123
+ print(f"Scraping attempt {self.attempts}...")
124
+ return self.autonomous_reasoning()
125
+ elif "generate_email" in llm_response.lower():
126
+ return self.format_email(llm_response)
127
+ elif "fallback" in llm_response.lower():
128
+ return self.generate_fallback_email()
129
+ else:
130
+ print("Error: Unrecognized instruction from LLM. Proceeding with available data.")
131
+ self.attempts += 1
132
+ return self.autonomous_reasoning()
133
+
134
  def format_email(self, llm_response):
135
  # Clean and format the email
136
  lines = [line.strip() for line in llm_response.split("\n") if line.strip()]
 
164
 
165
  return f"{formatted_email}{closing_section}\n{signature}"
166
 
167
+ def generate_fallback_email(self):
168
+ # Generate a basic email if max attempts are reached
169
+ return f"""Subject: Application for {self.role} at {self.company_name}
170
+
171
+ Dear Hiring Manager,
172
+
173
+ I am excited to apply for the {self.role} position at {self.company_name}. My experience and skills align with the role's requirements, and I am confident in my ability to contribute positively.
174
+
175
+ Best regards,
176
+ {self.user_name}
177
+ Email: {self.email}
178
+ Phone: {self.phone}
179
+ LinkedIn: {self.linkedin}
180
+ """
181
+
182
  # Gradio UI setup remains unchanged
183
  def gradio_ui():
184
  name_input = gr.Textbox(label="Your Name", placeholder="Enter your name")
 
200
  inputs=[name_input, company_input, role_input, email_input, phone_input, linkedin_input, word_limit_slider],
201
  outputs=[email_output],
202
  title="Email Writing AI Agent with ReAct",
203
+ description="Generates a job application email using dynamic and adaptive reasoning."
 
204
  )
 
205
  demo.launch()
206
 
207
  if __name__ == "__main__":