Spaces:
Sleeping
Sleeping
Commit
·
10493d1
1
Parent(s):
8ac5d88
Enhance .gitignore to include additional Python, environment, IDE, and model file exclusions. Refactor app.py to improve text generation pipeline initialization with better error handling and enhanced prompt structure for email generation. Update requirements.txt to specify minimum versions for dependencies, ensuring compatibility and stability.
Browse files- .gitignore +42 -1
- app.py +70 -33
- requirements.txt +6 -6
.gitignore
CHANGED
@@ -1,2 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
.env
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
*.so
|
6 |
+
.Python
|
7 |
+
env/
|
8 |
+
build/
|
9 |
+
develop-eggs/
|
10 |
+
dist/
|
11 |
+
downloads/
|
12 |
+
eggs/
|
13 |
+
.eggs/
|
14 |
+
lib/
|
15 |
+
lib64/
|
16 |
+
parts/
|
17 |
+
sdist/
|
18 |
+
var/
|
19 |
+
wheels/
|
20 |
+
*.egg-info/
|
21 |
+
.installed.cfg
|
22 |
+
*.egg
|
23 |
+
|
24 |
+
# Environment variables
|
25 |
.env
|
26 |
+
|
27 |
+
# Virtual Environment
|
28 |
+
venv/
|
29 |
+
ENV/
|
30 |
+
|
31 |
+
# IDE
|
32 |
+
.idea/
|
33 |
+
.vscode/
|
34 |
+
*.swp
|
35 |
+
*.swo
|
36 |
+
|
37 |
+
# Streamlit
|
38 |
+
.streamlit/
|
39 |
+
|
40 |
+
# Model files
|
41 |
+
*.pt
|
42 |
+
*.pth
|
43 |
+
*.bin
|
app.py
CHANGED
@@ -60,22 +60,35 @@ if st.session_state.parsed_cv:
|
|
60 |
if access_token:
|
61 |
@st.cache_resource
|
62 |
def initialize_pipeline(access_token):
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
text_gen_pipeline = initialize_pipeline(access_token)
|
72 |
|
73 |
@st.cache_resource
|
74 |
-
def
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
79 |
|
80 |
# Input job description
|
81 |
job_description = st.text_area("Enter the job description:", "")
|
@@ -83,27 +96,51 @@ if access_token:
|
|
83 |
# Display generated email
|
84 |
if st.button("Generate Email"):
|
85 |
if st.session_state.parsed_cv and job_description.strip():
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
f"Write a professional
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
else:
|
108 |
st.warning("Please upload your CV in the sidebar and enter a job description.")
|
109 |
else:
|
|
|
60 |
if access_token:
|
61 |
@st.cache_resource
|
62 |
def initialize_pipeline(access_token):
|
63 |
+
try:
|
64 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b-it", token=access_token)
|
65 |
+
model = AutoModelForCausalLM.from_pretrained(
|
66 |
+
"google/gemma-2b-it",
|
67 |
+
token=access_token,
|
68 |
+
device_map="auto" # Better device handling
|
69 |
+
)
|
70 |
+
return pipeline(
|
71 |
+
"text-generation",
|
72 |
+
model=model,
|
73 |
+
tokenizer=tokenizer,
|
74 |
+
max_new_tokens=512,
|
75 |
+
temperature=0.7, # Add temperature for better generation
|
76 |
+
do_sample=True, # Enable sampling
|
77 |
+
top_p=0.95 # Add top_p for better text quality
|
78 |
+
)
|
79 |
+
except Exception as e:
|
80 |
+
st.error(f"Failed to initialize the model: {str(e)}")
|
81 |
+
return None
|
82 |
|
83 |
text_gen_pipeline = initialize_pipeline(access_token)
|
84 |
|
85 |
@st.cache_resource
|
86 |
+
def initialize_memory():
|
87 |
+
return ConversationBufferMemory(
|
88 |
+
input_key="input",
|
89 |
+
output_key="output",
|
90 |
+
return_messages=True
|
91 |
+
)
|
92 |
|
93 |
# Input job description
|
94 |
job_description = st.text_area("Enter the job description:", "")
|
|
|
96 |
# Display generated email
|
97 |
if st.button("Generate Email"):
|
98 |
if st.session_state.parsed_cv and job_description.strip():
|
99 |
+
try:
|
100 |
+
memory = initialize_memory()
|
101 |
+
|
102 |
+
# Improved prompt template
|
103 |
+
prompt = f"""Task: Write a professional job application email.
|
104 |
+
|
105 |
+
CV Summary:
|
106 |
+
{st.session_state.parsed_cv}
|
107 |
+
|
108 |
+
Job Description:
|
109 |
+
{job_description}
|
110 |
+
|
111 |
+
Instructions: Write a concise and professional email expressing interest in the position.
|
112 |
+
Highlight relevant experience and skills from the CV that match the job requirements.
|
113 |
+
Keep the tone professional and enthusiastic.
|
114 |
+
|
115 |
+
Email:
|
116 |
+
"""
|
117 |
+
|
118 |
+
# Generate email using the pipeline
|
119 |
+
if text_gen_pipeline:
|
120 |
+
response = text_gen_pipeline(
|
121 |
+
prompt,
|
122 |
+
clean_up_tokenization_spaces=True,
|
123 |
+
return_full_text=False
|
124 |
+
)[0]['generated_text']
|
125 |
+
|
126 |
+
# Store in memory
|
127 |
+
memory.save_context(
|
128 |
+
{"input": f"Job Description: {job_description}"},
|
129 |
+
{"output": response}
|
130 |
+
)
|
131 |
+
|
132 |
+
# Display response
|
133 |
+
st.subheader("Generated Email:")
|
134 |
+
st.write(response)
|
135 |
+
|
136 |
+
# Display conversation history
|
137 |
+
st.subheader("Previous Generations:")
|
138 |
+
for entry in memory.load_memory_variables({})['history']:
|
139 |
+
st.write(entry)
|
140 |
+
else:
|
141 |
+
st.error("Text generation pipeline not properly initialized.")
|
142 |
+
except Exception as e:
|
143 |
+
st.error(f"Error generating email: {str(e)}")
|
144 |
else:
|
145 |
st.warning("Please upload your CV in the sidebar and enter a job description.")
|
146 |
else:
|
requirements.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
# add requirements
|
2 |
-
streamlit
|
3 |
-
python-dotenv
|
4 |
-
langchain
|
5 |
-
transformers
|
6 |
-
torch
|
7 |
-
PyPDF2
|
8 |
|
|
|
1 |
# add requirements
|
2 |
+
streamlit>=1.24.0
|
3 |
+
python-dotenv>=0.19.0
|
4 |
+
langchain>=0.1.0
|
5 |
+
transformers>=4.36.0
|
6 |
+
torch>=2.0.0
|
7 |
+
PyPDF2>=3.0.0
|
8 |
|