Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#757) Allow Users to Manually Edit the Generated Email in Cold Email Generator App #765

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 27 additions & 33 deletions Generative-AI/Cold-Email-Generator/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Chain:
def __init__(self):
self.llm = ChatGroq(temperature=0, groq_api_key=os.getenv("GROQ_API_KEY"), model_name="llama-3.1-70b-versatile")


def extract_jobs(self, cleaned_text):
prompt_extract = PromptTemplate.from_template(
"""
Expand All @@ -56,7 +55,6 @@ def extract_jobs(self, cleaned_text):
raise OutputParserException("Context too big. Unable to parse jobs.")
return res if isinstance(res, list) else [res]


def write_mail(self, job, links, user_name, user_about):
prompt_email = PromptTemplate.from_template(
"""
Expand All @@ -69,8 +67,6 @@ def write_mail(self, job, links, user_name, user_about):
Also, add the most relevant ones from the following links to showcase portfolio: {link_list}
Do not provide a preamble.
### EMAIL (NO PREAMBLE):


"""
)
chain_email = prompt_email | self.llm
Expand All @@ -85,35 +81,30 @@ def __init__(self):
if 'portfolio' not in st.session_state:
st.session_state['portfolio'] = []


def add_to_portfolio(self, skills, links):
"""Add the user's skills and portfolio links to temporary storage."""
if skills and links:
st.session_state['portfolio'].append({"skills": skills, "links": links})


def query_links(self, required_skills):
"""Query the temporary storage for relevant links based on provided skills."""
if not required_skills:
return []


# Find relevant portfolio entries based on skills
matched_links = []
for entry in st.session_state['portfolio']:
portfolio_skills = entry['skills']
if any(skill in portfolio_skills for skill in required_skills):
matched_links.append(entry['links'])


return matched_links[:2] # Return up to 2 matched links


# Function to create the Streamlit app interface
def create_streamlit_app(llm, portfolio, clean_text):
st.set_page_config(page_title="Cold Email Generator", page_icon="", layout="wide")


st.markdown("""
<style>
.main {
Expand Down Expand Up @@ -195,66 +186,69 @@ def create_streamlit_app(llm, portfolio, clean_text):
</style>
""", unsafe_allow_html=True)


st.markdown("<div class='title'>Cold Email Generator</div>", unsafe_allow_html=True)
st.markdown("<div class='subtitle'>Effortlessly craft professional cold emails for job applications based on job postings.</div>", unsafe_allow_html=True)


st.markdown("<div class='container'>", unsafe_allow_html=True)


user_name = st.text_input("Enter your name:", value=" ")
user_about = st.text_area(
"Enter a brief description about yourself:",
value=" "
)

user_about = st.text_area("Enter a brief description about yourself:", value=" ")

url_input = st.text_input("Enter a Job Post URL:", value=" ")


st.subheader("Enter Your Skills and Portfolio Links")
skills_input = st.text_area("Enter your skills (comma separated):", value="")
links_input = st.text_area("Enter your portfolio links (comma separated):", value="")


submit_button = st.button("Submit", key='submit_button', help="Click to generate the cold email")


if submit_button:
try:
skills_list = [skill.strip() for skill in skills_input.split(",")]
links_list = [link.strip() for link in links_input.split(",")]


portfolio.add_to_portfolio(skills_list, links_list)


loader = WebBaseLoader([url_input])
data = clean_text(loader.load().pop().page_content)
jobs = llm.extract_jobs(data)

# Initialize an empty email variable for editing
email_content = ""

for job in jobs:
job_skills = job.get('skills', [])
links = portfolio.query_links(job_skills)
email = llm.write_mail(job, links, user_name, user_about)
st.markdown(f"<div class='code-block'><pre>{email}</pre></div>", unsafe_allow_html=True)
email_content = llm.write_mail(job, links, user_name, user_about)
st.markdown(f"<div class='code-block'><pre>{email_content}</pre></div>", unsafe_allow_html=True)

# Add a text area for manual editing of the generated email
edited_email = st.text_area("Edit the generated email:", value=email_content, height=200)

except Exception as e:
st.error(f"An Error Occurred: {e}")
# Options to download as txt file
col1, col2, col3 = st.columns(3)


st.markdown("</div>", unsafe_allow_html=True)

with col2:
st.download_button(
label="Download Email",
data=edited_email,
file_name="email.txt",
mime="text/plain"
)




except Exception as e:
st.error(f"An error occurred: {e}")

st.markdown("</div>", unsafe_allow_html=True)

# Main function to run the app
if __name__ == "__main__":
chain = Chain()
portfolio = Portfolio()

# Initialize classes and run the Streamlit app
llm = Chain()
portfolio = Portfolio()

create_streamlit_app(chain, portfolio, clean_text)
if __name__ == "__main__":
create_streamlit_app(llm, portfolio, clean_text)