siddhartharya
commited on
Commit
•
7ea79b0
1
Parent(s):
bd877a9
Update app.py
Browse files
app.py
CHANGED
@@ -141,4 +141,62 @@ class EmailAgent:
|
|
141 |
|
142 |
data = {
|
143 |
"messages": [{"role": "user", "content": prompt}],
|
144 |
-
"model": "llama3-8b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
data = {
|
143 |
"messages": [{"role": "user", "content": prompt}],
|
144 |
+
"model": "llama3-8b-8192"
|
145 |
+
}
|
146 |
+
|
147 |
+
response = requests.post(url, headers=headers, json=data)
|
148 |
+
if response.status_code == 200:
|
149 |
+
return response.json()["choices"][0]["message"]["content"].strip()
|
150 |
+
else:
|
151 |
+
print(f"Error: {response.status_code}, {response.text}")
|
152 |
+
return "Error generating email. Please check your API key or try again later."
|
153 |
+
|
154 |
+
# Main loop following ReAct pattern
|
155 |
+
def run(self):
|
156 |
+
self.reason_about_data() # Reasoning step
|
157 |
+
self.fetch_linkedin_data() # Fetch LinkedIn data
|
158 |
+
self.fetch_company_info() # Fetch company data
|
159 |
+
# Scrape the company's website for role-specific information or use defaults
|
160 |
+
if not self.scrape_role_from_website():
|
161 |
+
self.use_default_role_description()
|
162 |
+
# Reflect on whether the data is sufficient
|
163 |
+
if self.reflect_on_data():
|
164 |
+
return self.generate_email() # Final action: generate email
|
165 |
+
else:
|
166 |
+
return "Error: Not enough data to generate the email."
|
167 |
+
|
168 |
+
# Define the Gradio interface and the main app logic
|
169 |
+
def gradio_ui():
|
170 |
+
# Input fields
|
171 |
+
name_input = gr.Textbox(label="Your Name", placeholder="Enter your name")
|
172 |
+
company_input = gr.Textbox(label="Company Name or URL", placeholder="Enter the company name or website URL")
|
173 |
+
role_input = gr.Textbox(label="Role Applying For", placeholder="Enter the role you are applying for")
|
174 |
+
email_input = gr.Textbox(label="Your Email Address", placeholder="Enter your email address")
|
175 |
+
phone_input = gr.Textbox(label="Your Phone Number", placeholder="Enter your phone number")
|
176 |
+
linkedin_input = gr.Textbox(label="Your LinkedIn URL", placeholder="Enter your LinkedIn profile URL")
|
177 |
+
word_limit_slider = gr.Slider(minimum=50, maximum=300, step=10, label="Email Word Limit", value=150) # Word limit slider
|
178 |
+
|
179 |
+
# Output field
|
180 |
+
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
181 |
+
|
182 |
+
# Function to create and run the email agent
|
183 |
+
def create_email(name, company_name, role, email, phone, linkedin_url, word_limit):
|
184 |
+
agent = EmailAgent(linkedin_url, company_name, role, word_limit, name, email, phone, linkedin_url)
|
185 |
+
return agent.run()
|
186 |
+
|
187 |
+
# Gradio interface
|
188 |
+
demo = gr.Interface(
|
189 |
+
fn=create_email,
|
190 |
+
inputs=[name_input, company_input, role_input, email_input, phone_input, linkedin_input, word_limit_slider],
|
191 |
+
outputs=[email_output],
|
192 |
+
title="Email Writing AI Agent with ReAct",
|
193 |
+
description="Generate a professional email for a job application using LinkedIn data, company info, and role description.",
|
194 |
+
allow_flagging="never"
|
195 |
+
)
|
196 |
+
|
197 |
+
# Launch the Gradio app
|
198 |
+
demo.launch()
|
199 |
+
|
200 |
+
# Start the Gradio app when running the script
|
201 |
+
if __name__ == "__main__":
|
202 |
+
gradio_ui()
|