Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +102 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import together
|
3 |
+
import PyPDF2
|
4 |
+
import io
|
5 |
+
|
6 |
+
# Initialize Together AI client
|
7 |
+
client=together.Together(api_key="8969731d768db64b1406eaa5e70bae31bcb4cbf57719295a03aed2ebfa45fe51")
|
8 |
+
|
9 |
+
def read_pdf(pdf_file):
|
10 |
+
"""Extract text from uploaded PDF file"""
|
11 |
+
if pdf_file is not None:
|
12 |
+
pdf_reader = PyPDF2.PdfReader(io.BytesIO(pdf_file.getvalue()))
|
13 |
+
text = ""
|
14 |
+
for page in pdf_reader.pages:
|
15 |
+
text += page.extract_text()
|
16 |
+
return text
|
17 |
+
return None
|
18 |
+
|
19 |
+
def get_ai_response(prompt):
|
20 |
+
"""Get response from Together AI API"""
|
21 |
+
response = client.chat.completions.create(
|
22 |
+
# prompt=prompt,
|
23 |
+
model="meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo", # or your preferred model
|
24 |
+
messages=[{"role": "user", "content": prompt}],
|
25 |
+
max_tokens=1024,
|
26 |
+
temperature=0.7,
|
27 |
+
)
|
28 |
+
print(response)
|
29 |
+
return response.choices[0].message.content
|
30 |
+
|
31 |
+
def create_prompt(resume_text, job_description, user_question):
|
32 |
+
"""Create prompt based on available information"""
|
33 |
+
prompt = "You are a helpful career advisor. "
|
34 |
+
|
35 |
+
if resume_text:
|
36 |
+
prompt += f"\nResume Content:\n{resume_text}\n"
|
37 |
+
|
38 |
+
if job_description:
|
39 |
+
prompt += f"\nJob Description:\n{job_description}\n"
|
40 |
+
|
41 |
+
prompt += f"\nUser Question: {user_question}\n"
|
42 |
+
prompt += "\nPlease provide a detailed and helpful response: "
|
43 |
+
|
44 |
+
return prompt
|
45 |
+
|
46 |
+
# Streamlit UI
|
47 |
+
st.title("Resume Bot Assistant")
|
48 |
+
|
49 |
+
# Initialize session state for chat history
|
50 |
+
if 'messages' not in st.session_state:
|
51 |
+
st.session_state.messages = []
|
52 |
+
|
53 |
+
# Sidebar
|
54 |
+
with st.sidebar:
|
55 |
+
st.header("Upload Documents")
|
56 |
+
|
57 |
+
# Resume upload
|
58 |
+
resume_file = st.file_uploader("Upload Resume (PDF)", type=['pdf'])
|
59 |
+
resume_text = None
|
60 |
+
if resume_file:
|
61 |
+
resume_text = read_pdf(resume_file)
|
62 |
+
st.success("Resume uploaded successfully!")
|
63 |
+
else:
|
64 |
+
st.warning("Please upload your resume")
|
65 |
+
|
66 |
+
# Job description input
|
67 |
+
job_description = st.text_area("Enter Job Description")
|
68 |
+
|
69 |
+
# Display chat messages
|
70 |
+
for message in st.session_state.messages:
|
71 |
+
with st.chat_message(message["role"]):
|
72 |
+
st.markdown(message["content"])
|
73 |
+
|
74 |
+
# User input
|
75 |
+
if prompt := st.chat_input("Ask a question about your resume or the job..."):
|
76 |
+
# Add user message to chat history
|
77 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
78 |
+
with st.chat_message("user"):
|
79 |
+
st.markdown(prompt)
|
80 |
+
|
81 |
+
# Check if resume is uploaded
|
82 |
+
if not resume_text:
|
83 |
+
with st.chat_message("assistant"):
|
84 |
+
error_message = "Please upload your resume first to get personalized advice."
|
85 |
+
st.session_state.messages.append({"role": "assistant", "content": error_message})
|
86 |
+
st.markdown(error_message)
|
87 |
+
else:
|
88 |
+
# Generate AI response
|
89 |
+
with st.chat_message("assistant"):
|
90 |
+
with st.spinner("Thinking..."):
|
91 |
+
# Create full prompt with context
|
92 |
+
full_prompt = create_prompt(resume_text, job_description, prompt)
|
93 |
+
response = get_ai_response(full_prompt)
|
94 |
+
|
95 |
+
# Add assistant message to chat history
|
96 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
97 |
+
st.markdown(response)
|
98 |
+
|
99 |
+
# Add a reset button
|
100 |
+
if st.button("Reset Chat"):
|
101 |
+
st.session_state.messages = []
|
102 |
+
st.experimental_rerun()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
togeather
|
3 |
+
pyPDF2
|