-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_old.py
122 lines (104 loc) · 4.74 KB
/
app_old.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# app.py
import streamlit as st
import os
import tempfile
from dotenv import load_dotenv
from crewai import Agent, Task, Crew
from agents import researcher, profiler, resume_strategist, linkedin_strategist, interview_preparer, faq_finder
from tasks import (
research_task, profile_task, resume_strategy_task, linkedin_strategy_task,
linkedin_message_task, interview_preparation_task, previously_asked_questions,
leetcode_questions_plan
)
from utils import PDFReadTool, search_tool, search_tool_serp, scrape_tool, semantic_search_resume
from openai import APIError
# Load environment variables
load_dotenv()
# Set up Streamlit page
st.set_page_config(page_title="Job Application Assistant", page_icon="🚀", layout="wide")
st.title("Job Application Assistant")
# Input fields
job_posting_url = st.text_input("Job Posting URL")
personal_profile = st.text_area("Personal Profile")
github_url = st.text_input("GitHub URL")
linkedin_url = st.text_input("LinkedIn URL")
uploaded_resume = st.file_uploader("Upload Resume (PDF)", type="pdf")
interested_field = st.text_input("Interested Field")
# Set up OpenAI API key
openai_api_key = os.getenv('OPENAI_API_KEY')
if not openai_api_key:
openai_api_key = st.text_input("Enter your OpenAI API key", type="password")
if not openai_api_key:
st.warning("Please enter your OpenAI API key to proceed.")
st.stop()
# Set environment variables for CrewAI
os.environ['OPENAI_API_KEY'] = openai_api_key
os.environ['OPENAI_MODEL_NAME'] = 'gpt-4o'
def display_file_content(file_name, subheader):
if os.path.exists(file_name):
with open(file_name, "r") as f:
st.subheader(subheader)
st.markdown(f.read())
else:
st.warning(f"{subheader} not generated. The file {file_name} was not found.")
def process_crew_task(crew, inputs, task_name):
try:
return crew.kickoff(inputs=inputs)
except APIError as e:
st.error(f"Error in {task_name}: {str(e)}")
return None
except Exception as e:
st.error(f"An unexpected error occurred in {task_name}: {str(e)}")
return None
if st.button("Process Application"):
resume_content = None
if uploaded_resume:
pdf_tool = PDFReadTool()
with tempfile.NamedTemporaryFile(delete=False, suffix='.pdf') as tmp_file:
tmp_file.write(uploaded_resume.getvalue())
tmp_file_path = tmp_file.name
resume_content = pdf_tool._run(tmp_file_path)
os.unlink(tmp_file_path) # Remove the temporary file
job_application_inputs = {
'job_posting_url': job_posting_url,
'personal_profile': personal_profile,
'github_url': github_url,
'linkedin_url': linkedin_url,
'resume_content': resume_content,
'interested_field': interested_field
}
job_application_crew = Crew(
agents=[researcher, profiler, resume_strategist, linkedin_strategist, interview_preparer],
tasks=[research_task, profile_task, resume_strategy_task, linkedin_message_task, interview_preparation_task],
verbose=True
)
leetcode_crew = Crew(
agents=[faq_finder],
tasks=[previously_asked_questions, leetcode_questions_plan],
verbose=True
)
with st.spinner("Processing your application..."):
result_linkedin = process_crew_task(job_application_crew, job_application_inputs, "Job Application")
result_leetcode = process_crew_task(leetcode_crew, job_application_inputs, "LeetCode Preparation")
if result_linkedin or result_leetcode:
st.success("Processing complete!")
# Display results
st.header("Results")
display_file_content("tailored_resume.md", "Tailored Resume")
display_file_content("interview_preparation.md", "Interview Preparation")
display_file_content("linkedin_about.md", "LinkedIn About Section")
display_file_content("linkedin_message.md", "LinkedIn Message")
display_file_content("faq_questions.md", "Frequently Asked Questions")
display_file_content("leetcode_plan.md", "LeetCode Plan")
# Display raw results if files are not generated
if not any(os.path.exists(f) for f in ["tailored_resume.md", "interview_preparation.md", "linkedin_about.md", "linkedin_message.md", "faq_questions.md", "leetcode_plan.md"]):
st.subheader("Raw Results")
if result_linkedin:
st.write("LinkedIn Crew Results:")
st.write(result_linkedin)
if result_leetcode:
st.write("LeetCode Crew Results:")
st.write(result_leetcode)
else:
st.error("Processing failed. Please try again with different inputs or contact support.")
# No need for cleanup at the end as we're using a context manager for the temporary file