Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,255 +1,139 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from langchain.chains import LLMChain
|
| 3 |
from langchain.prompts import PromptTemplate
|
| 4 |
-
from langchain.
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# Streamlit App Configuration
|
| 18 |
-
st.set_page_config(page_title="DocuMentorAI", layout="wide", page_icon="📄")
|
| 19 |
-
st.title("📄 DocuMentorAI")
|
| 20 |
-
st.write("Generate professional application documents with ease!")
|
| 21 |
-
|
| 22 |
-
# Custom CSS for better UI
|
| 23 |
-
st.markdown("""
|
| 24 |
-
<style>
|
| 25 |
-
.stTextArea textarea { font-size: 16px !important; }
|
| 26 |
-
.stButton button { width: 100%; background-color: #4CAF50; color: white; }
|
| 27 |
-
.stDownloadButton button { width: 100%; background-color: #008CBA; color: white; }
|
| 28 |
-
.stMarkdown { font-size: 18px; }
|
| 29 |
-
</style>
|
| 30 |
-
""", unsafe_allow_html=True)
|
| 31 |
-
|
| 32 |
-
# Text Input for Job Opening Details
|
| 33 |
-
st.subheader("📢 Enter Opening Details")
|
| 34 |
-
job_opening_text = st.text_area(
|
| 35 |
-
"Paste the job/research opening details here...",
|
| 36 |
-
height=150,
|
| 37 |
-
placeholder="Example: 'We are hiring a Research Assistant at XYZ University. The ideal candidate has experience in machine learning and data analysis...'"
|
| 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 |
-
# Extract professor details if job opening is uploaded
|
| 95 |
-
professor_name, university_name = extract_professor_details(job_opening_text)
|
| 96 |
-
|
| 97 |
-
# LLM Prompt Templates
|
| 98 |
-
email_template = PromptTemplate.from_template("""
|
| 99 |
-
Write a professional cold email for a research position.
|
| 100 |
-
- Address the professor formally.
|
| 101 |
-
- Introduce yourself and academic background.
|
| 102 |
-
- Express interest in their research.
|
| 103 |
-
- Highlight key skills from your CV.
|
| 104 |
-
- Conclude with a polite request.
|
| 105 |
-
### Input:
|
| 106 |
-
- Professor: {professor_name}
|
| 107 |
-
- University: {university_name}
|
| 108 |
-
- Research Interests: {research_interests}
|
| 109 |
-
- Why This Lab: {reason}
|
| 110 |
-
- CV Highlights: {resume_text}
|
| 111 |
-
### Output:
|
| 112 |
-
A well-structured, professional cold email.
|
| 113 |
-
""")
|
| 114 |
-
|
| 115 |
-
cover_letter_template = PromptTemplate.from_template("""
|
| 116 |
-
Write a compelling job application cover letter.
|
| 117 |
-
- Address the employer formally.
|
| 118 |
-
- Mention job title and where you found it.
|
| 119 |
-
- Highlight key skills and experiences.
|
| 120 |
-
- Relate background to the company.
|
| 121 |
-
- Conclude with enthusiasm.
|
| 122 |
-
### Input:
|
| 123 |
-
- Job Title: {job_title}
|
| 124 |
-
- Company: {company}
|
| 125 |
-
- Key Skills: {key_skills}
|
| 126 |
-
- CV Highlights: {resume_text}
|
| 127 |
-
### Output:
|
| 128 |
-
A strong, well-formatted cover letter.
|
| 129 |
-
""")
|
| 130 |
-
|
| 131 |
-
research_statement_template = PromptTemplate.from_template("""
|
| 132 |
-
Write a research statement for Ph.D. applications.
|
| 133 |
-
- Discuss research background and motivation.
|
| 134 |
-
- Explain key research experiences and findings.
|
| 135 |
-
- Outline future research interests and goals.
|
| 136 |
-
- Highlight contributions to the field.
|
| 137 |
-
### Input:
|
| 138 |
-
- Research Background: {research_background}
|
| 139 |
-
- Key Research Projects: {key_projects}
|
| 140 |
-
- Future Goals: {future_goals}
|
| 141 |
-
### Output:
|
| 142 |
-
A well-structured, professional research statement.
|
| 143 |
-
""")
|
| 144 |
-
|
| 145 |
-
sop_template = PromptTemplate.from_template("""
|
| 146 |
-
Write a compelling Statement of Purpose (SOP).
|
| 147 |
-
- Introduce motivation for graduate studies.
|
| 148 |
-
- Discuss academic background.
|
| 149 |
-
- Explain relevant experiences and research.
|
| 150 |
-
- Outline career goals.
|
| 151 |
-
- Justify fit for the program.
|
| 152 |
-
### Input:
|
| 153 |
-
- Motivation: {motivation}
|
| 154 |
-
- Academic Background: {academic_background}
|
| 155 |
-
- Research & Projects: {research_experiences}
|
| 156 |
-
- Career Goals: {career_goals}
|
| 157 |
-
- Why This Program: {why_this_program}
|
| 158 |
-
### Output:
|
| 159 |
-
A well-structured SOP.
|
| 160 |
-
""")
|
| 161 |
-
|
| 162 |
-
# LangChain Chains
|
| 163 |
-
email_chain = LLMChain(llm=llm, prompt=email_template)
|
| 164 |
-
cover_letter_chain = LLMChain(llm=llm, prompt=cover_letter_template)
|
| 165 |
-
research_statement_chain = LLMChain(llm=llm, prompt=research_statement_template)
|
| 166 |
-
sop_chain = LLMChain(llm=llm, prompt=sop_template)
|
| 167 |
-
|
| 168 |
-
# User Inputs
|
| 169 |
-
st.subheader("📩 Generate Application Documents")
|
| 170 |
-
tab1, tab2, tab3, tab4 = st.tabs(["Cold Email", "Cover Letter", "Research Statement", "SOP"])
|
| 171 |
-
|
| 172 |
-
# Cold Email Generation
|
| 173 |
-
with tab1:
|
| 174 |
-
st.write(f"🧑🏫 **Detected Professor:** {professor_name} at {university_name}")
|
| 175 |
-
research_interests = st.text_area("Research Interests", placeholder="Example: Machine Learning, Data Analysis, etc.")
|
| 176 |
-
reason = st.text_area("Why this professor/lab?", placeholder="Example: I am particularly interested in your work on...")
|
| 177 |
-
|
| 178 |
-
if st.button("Generate Cold Email"):
|
| 179 |
-
if not job_opening_text or not cv_resume_text:
|
| 180 |
-
st.error("Please provide job opening details and upload your CV/Resume.")
|
| 181 |
-
else:
|
| 182 |
-
with st.spinner("Generating Cold Email..."):
|
| 183 |
-
email = email_chain.run({
|
| 184 |
-
"professor_name": professor_name,
|
| 185 |
-
"university_name": university_name,
|
| 186 |
-
"research_interests": research_interests,
|
| 187 |
-
"reason": reason,
|
| 188 |
-
"resume_text": cv_resume_text
|
| 189 |
-
})
|
| 190 |
-
st.markdown("**Generated Cold Email:**")
|
| 191 |
-
st.markdown(email)
|
| 192 |
-
st.download_button("Download Email", email, file_name="cold_email.txt")
|
| 193 |
-
|
| 194 |
-
# Cover Letter Generation
|
| 195 |
-
with tab2:
|
| 196 |
-
job_title = st.text_input("Job Title", placeholder="Example: Research Assistant")
|
| 197 |
-
company_name = university_name if university_name != "Not Found" else st.text_input("Company/University", placeholder="Example: XYZ University")
|
| 198 |
-
key_skills = st.text_area("Key Skills", placeholder="Example: Python, Machine Learning, Data Analysis")
|
| 199 |
|
| 200 |
if st.button("Generate Cover Letter"):
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
with tab3:
|
| 217 |
-
research_background = st.text_area("Research Background", placeholder="Example: My research focuses on...")
|
| 218 |
-
key_projects = st.text_area("Key Research Projects", placeholder="Example: Developed a machine learning model for...")
|
| 219 |
-
future_goals = st.text_area("Future Research Goals", placeholder="Example: I aim to explore...")
|
| 220 |
|
| 221 |
if st.button("Generate Research Statement"):
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
why_this_program = st.text_area("Why This Program", placeholder="Example: This program aligns with my research interests because...")
|
| 239 |
|
| 240 |
if st.button("Generate SOP"):
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
st.markdown(sop)
|
| 251 |
-
st.download_button("Download SOP", sop, file_name="sop.txt")
|
| 252 |
-
|
| 253 |
-
# Reset Button
|
| 254 |
-
if st.button("🔄 Reset All Inputs and Outputs"):
|
| 255 |
-
st.experimental_rerun()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from langchain.chat_models import ChatOpenAI
|
| 3 |
from langchain.chains import LLMChain
|
| 4 |
from langchain.prompts import PromptTemplate
|
| 5 |
+
from langchain.memory import ConversationBufferMemory
|
| 6 |
+
|
| 7 |
+
# Initialize OpenAI LLM
|
| 8 |
+
llm = ChatOpenAI(model="gpt-4", temperature=0.7)
|
| 9 |
+
|
| 10 |
+
# Define Prompts
|
| 11 |
+
email_prompt = PromptTemplate(
|
| 12 |
+
input_variables=["professor_name", "university_name", "research_interests", "reason", "resume_text"],
|
| 13 |
+
template="""
|
| 14 |
+
Write a professional cold email to {professor_name} at {university_name} expressing interest in their research.
|
| 15 |
+
Highlight relevant research interests: {research_interests}.
|
| 16 |
+
Explain why you want to work with them: {reason}. Keep it concise and professional.
|
| 17 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
+
cover_letter_prompt = PromptTemplate(
|
| 20 |
+
input_variables=["job_title", "company", "key_skills", "resume_text"],
|
| 21 |
+
template="""
|
| 22 |
+
Write a professional cover letter for the {job_title} position at {company}.
|
| 23 |
+
Highlight key skills: {key_skills}. Keep it formal and tailored to the job.
|
| 24 |
+
"""
|
| 25 |
+
)
|
| 26 |
+
research_statement_prompt = PromptTemplate(
|
| 27 |
+
input_variables=["research_background", "key_projects", "future_goals"],
|
| 28 |
+
template="""
|
| 29 |
+
Write a research statement based on the following:
|
| 30 |
+
- Background: {research_background}
|
| 31 |
+
- Key Projects: {key_projects}
|
| 32 |
+
- Future Research Goals: {future_goals}
|
| 33 |
+
Keep it structured and professional.
|
| 34 |
+
"""
|
| 35 |
+
)
|
| 36 |
+
sop_prompt = PromptTemplate(
|
| 37 |
+
input_variables=["motivation", "academic_background", "research_experiences", "career_goals", "why_this_program"],
|
| 38 |
+
template="""
|
| 39 |
+
Write a Statement of Purpose (SOP) with:
|
| 40 |
+
- Motivation: {motivation}
|
| 41 |
+
- Academic Background: {academic_background}
|
| 42 |
+
- Research Experiences: {research_experiences}
|
| 43 |
+
- Career Goals: {career_goals}
|
| 44 |
+
- Why this program: {why_this_program}
|
| 45 |
+
Ensure it is compelling and well-structured.
|
| 46 |
+
"""
|
| 47 |
)
|
| 48 |
|
| 49 |
+
# Create LLM Chains
|
| 50 |
+
email_chain = LLMChain(llm=llm, prompt=email_prompt, memory=ConversationBufferMemory(memory_key="history"))
|
| 51 |
+
cover_letter_chain = LLMChain(llm=llm, prompt=cover_letter_prompt, memory=ConversationBufferMemory(memory_key="history"))
|
| 52 |
+
research_statement_chain = LLMChain(llm=llm, prompt=research_statement_prompt, memory=ConversationBufferMemory(memory_key="history"))
|
| 53 |
+
sop_chain = LLMChain(llm=llm, prompt=sop_prompt, memory=ConversationBufferMemory(memory_key="history"))
|
| 54 |
+
|
| 55 |
+
# Streamlit App
|
| 56 |
+
st.title("AI-Powered Academic & Job Application Generator")
|
| 57 |
+
|
| 58 |
+
# File Upload for Resume
|
| 59 |
+
st.sidebar.header("Upload Your Resume (Optional)")
|
| 60 |
+
uploaded_file = st.sidebar.file_uploader("Upload a .txt file", type=["txt"])
|
| 61 |
+
|
| 62 |
+
cv_resume_text = ""
|
| 63 |
+
if uploaded_file is not None:
|
| 64 |
+
cv_resume_text = uploaded_file.read().decode("utf-8")
|
| 65 |
+
|
| 66 |
+
# Tabs for Different Documents
|
| 67 |
+
tabs = st.tabs(["Cold Email", "Cover Letter", "Research Statement", "Statement of Purpose"])
|
| 68 |
+
|
| 69 |
+
# Cold Email Generator
|
| 70 |
+
with tabs[0]:
|
| 71 |
+
st.header("Generate a Cold Email")
|
| 72 |
+
professor_name = st.text_input("Professor's Name")
|
| 73 |
+
university_name = st.text_input("University Name")
|
| 74 |
+
research_interests = st.text_area("Your Research Interests")
|
| 75 |
+
reason = st.text_area("Why do you want to work with this professor?")
|
| 76 |
+
|
| 77 |
+
if st.button("Generate Email"):
|
| 78 |
+
email_output = email_chain.run({
|
| 79 |
+
"professor_name": professor_name,
|
| 80 |
+
"university_name": university_name,
|
| 81 |
+
"research_interests": research_interests,
|
| 82 |
+
"reason": reason,
|
| 83 |
+
"resume_text": cv_resume_text
|
| 84 |
+
}).strip()
|
| 85 |
+
st.markdown(email_output)
|
| 86 |
+
st.download_button("Download Email", email_output, file_name="cold_email.txt")
|
| 87 |
+
|
| 88 |
+
# Cover Letter Generator
|
| 89 |
+
with tabs[1]:
|
| 90 |
+
st.header("Generate a Cover Letter")
|
| 91 |
+
job_title = st.text_input("Job Title")
|
| 92 |
+
company_name = st.text_input("Company Name")
|
| 93 |
+
key_skills = st.text_area("Key Skills for the Job")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
if st.button("Generate Cover Letter"):
|
| 96 |
+
cover_letter_output = cover_letter_chain.run({
|
| 97 |
+
"job_title": job_title,
|
| 98 |
+
"company": company_name,
|
| 99 |
+
"key_skills": key_skills,
|
| 100 |
+
"resume_text": cv_resume_text
|
| 101 |
+
}).strip()
|
| 102 |
+
st.markdown(cover_letter_output)
|
| 103 |
+
st.download_button("Download Cover Letter", cover_letter_output, file_name="cover_letter.txt")
|
| 104 |
+
|
| 105 |
+
# Research Statement Generator
|
| 106 |
+
with tabs[2]:
|
| 107 |
+
st.header("Generate a Research Statement")
|
| 108 |
+
research_background = st.text_area("Your Research Background")
|
| 109 |
+
key_projects = st.text_area("Key Projects You've Worked On")
|
| 110 |
+
future_goals = st.text_area("Future Research Goals")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
if st.button("Generate Research Statement"):
|
| 113 |
+
research_statement_output = research_statement_chain.run({
|
| 114 |
+
"research_background": research_background,
|
| 115 |
+
"key_projects": key_projects,
|
| 116 |
+
"future_goals": future_goals
|
| 117 |
+
}).strip()
|
| 118 |
+
st.markdown(research_statement_output)
|
| 119 |
+
st.download_button("Download Research Statement", research_statement_output, file_name="research_statement.txt")
|
| 120 |
+
|
| 121 |
+
# Statement of Purpose Generator
|
| 122 |
+
with tabs[3]:
|
| 123 |
+
st.header("Generate a Statement of Purpose (SOP)")
|
| 124 |
+
motivation = st.text_area("Your Motivation for Graduate Studies")
|
| 125 |
+
academic_background = st.text_area("Your Academic Background")
|
| 126 |
+
research_experiences = st.text_area("Your Research Experiences")
|
| 127 |
+
career_goals = st.text_area("Your Career Goals")
|
| 128 |
+
why_this_program = st.text_area("Why This Program?")
|
|
|
|
| 129 |
|
| 130 |
if st.button("Generate SOP"):
|
| 131 |
+
sop_output = sop_chain.run({
|
| 132 |
+
"motivation": motivation,
|
| 133 |
+
"academic_background": academic_background,
|
| 134 |
+
"research_experiences": research_experiences,
|
| 135 |
+
"career_goals": career_goals,
|
| 136 |
+
"why_this_program": why_this_program
|
| 137 |
+
}).strip()
|
| 138 |
+
st.markdown(sop_output)
|
| 139 |
+
st.download_button("Download SOP", sop_output, file_name="sop.txt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|