AdithyaSNair commited on
Commit
364ed89
·
verified ·
1 Parent(s): 7f28832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import streamlit as st
2
  from streamlit_option_menu import option_menu
3
  from langchain_groq import ChatGroq
@@ -15,6 +17,11 @@ import yaml
15
  import json
16
  import os
17
 
 
 
 
 
 
18
  GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
19
  RAPIDAPI_KEY = st.secrets["RAPIDAPI_KEY"]
20
 
@@ -24,6 +31,10 @@ llm = ChatGroq(
24
  model_name="llama-3.1-70b-versatile"
25
  )
26
 
 
 
 
 
27
  def load_authentication():
28
  """
29
  Loads and parses authentication configurations from Streamlit secrets.
@@ -31,24 +42,25 @@ def load_authentication():
31
  Returns:
32
  dict: Parsed authentication configurations with 'credentials' and 'cookie' as dictionaries.
33
  """
34
- # Load authentication config from secrets.toml
35
- config = st.secrets["auth"]
 
36
 
37
  # Parse credentials from YAML string to dict
38
  try:
39
- config['credentials'] = yaml.safe_load(config['credentials'])
40
  except yaml.YAMLError as e:
41
  st.error(f"Error parsing credentials: {e}")
42
  return {}
43
 
44
  # Parse cookie from JSON string to dict
45
  try:
46
- config['cookie'] = json.loads(config['cookie'])
47
  except json.JSONDecodeError as e:
48
  st.error(f"Error parsing cookie configuration: {e}")
49
  return {}
50
 
51
- return config
52
 
53
  config = load_authentication()
54
 
@@ -70,7 +82,7 @@ if config:
70
  # -------------------------------
71
  # Define Helper Functions with Caching
72
  # -------------------------------
73
-
74
  @st.cache_data(ttl=3600)
75
  def extract_text_from_pdf(pdf_file):
76
  """
@@ -85,7 +97,7 @@ if config:
85
  except Exception as e:
86
  st.error(f"Error extracting text from PDF: {e}")
87
  return ""
88
-
89
  @st.cache_data(ttl=3600)
90
  def extract_job_description(job_link):
91
  """
@@ -104,7 +116,7 @@ if config:
104
  except Exception as e:
105
  st.error(f"Error fetching job description: {e}")
106
  return ""
107
-
108
  @st.cache_data(ttl=3600)
109
  def extract_requirements(job_description):
110
  """
@@ -127,7 +139,7 @@ if config:
127
  except Exception as e:
128
  st.error(f"Error extracting requirements: {e}")
129
  return ""
130
-
131
  @st.cache_data(ttl=3600)
132
  def generate_email(job_description, requirements, resume_text):
133
  """
@@ -161,7 +173,7 @@ if config:
161
  except Exception as e:
162
  st.error(f"Error generating email: {e}")
163
  return ""
164
-
165
  @st.cache_data(ttl=3600)
166
  def generate_cover_letter(job_description, requirements, resume_text):
167
  """
@@ -199,7 +211,7 @@ if config:
199
  except Exception as e:
200
  st.error(f"Error generating cover letter: {e}")
201
  return ""
202
-
203
  @st.cache_data(ttl=3600)
204
  def extract_skills(text):
205
  """
@@ -223,7 +235,7 @@ if config:
223
  except Exception as e:
224
  st.error(f"Error extracting skills: {e}")
225
  return []
226
-
227
  @st.cache_data(ttl=3600)
228
  def suggest_keywords(resume_text, job_description=None):
229
  """
@@ -249,7 +261,7 @@ if config:
249
  except Exception as e:
250
  st.error(f"Error suggesting keywords: {e}")
251
  return []
252
-
253
  @st.cache_data(ttl=3600)
254
  def get_job_recommendations(job_title, location="India"):
255
  """
@@ -292,7 +304,7 @@ if config:
292
  except Exception as err:
293
  st.error(f"An error occurred: {err}")
294
  return {}
295
-
296
  def create_skill_distribution_chart(skills):
297
  """
298
  Creates a bar chart showing the distribution of skills.
@@ -303,7 +315,7 @@ if config:
303
  df = pd.DataFrame(list(skill_counts.items()), columns=['Skill', 'Count'])
304
  fig = px.bar(df, x='Skill', y='Count', title='Skill Distribution')
305
  return fig
306
-
307
  def create_experience_timeline(resume_text):
308
  """
309
  Creates an experience timeline from the resume text.
@@ -346,7 +358,7 @@ if config:
346
  except Exception as e:
347
  st.error(f"Error creating experience timeline: {e}")
348
  return None
349
-
350
  def parse_duration(duration_str):
351
  """
352
  Parses duration strings like '2 years' or '6 months' into float years.
@@ -362,7 +374,7 @@ if config:
362
  return 0
363
  except:
364
  return 0
365
-
366
  # -------------------------------
367
  # Database Functions
368
  # -------------------------------
@@ -471,7 +483,7 @@ if config:
471
  except Exception as e:
472
  st.error(f"Error generating learning path: {e}")
473
  return ""
474
-
475
  # -------------------------------
476
  # Page Functions
477
  # -------------------------------
@@ -1193,7 +1205,6 @@ if config:
1193
  elif selected == "Help":
1194
  help_page()
1195
 
1196
-
1197
 
1198
  if __name__ == "__main__":
1199
  main_app()
@@ -1201,4 +1212,4 @@ if config:
1201
  elif authentication_status == False:
1202
  st.error('Username/password is incorrect')
1203
  elif authentication_status == None:
1204
- st.warning('Please enter your username and password')
 
1
+ # app.py
2
+
3
  import streamlit as st
4
  from streamlit_option_menu import option_menu
5
  from langchain_groq import ChatGroq
 
17
  import json
18
  import os
19
 
20
+ # -------------------------------
21
+ # Initialize the LLM with Groq API Key
22
+ # -------------------------------
23
+
24
+ # Ensure API keys are stored securely using secrets.toml
25
  GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
26
  RAPIDAPI_KEY = st.secrets["RAPIDAPI_KEY"]
27
 
 
31
  model_name="llama-3.1-70b-versatile"
32
  )
33
 
34
+ # -------------------------------
35
+ # Authentication Setup
36
+ # -------------------------------
37
+
38
  def load_authentication():
39
  """
40
  Loads and parses authentication configurations from Streamlit secrets.
 
42
  Returns:
43
  dict: Parsed authentication configurations with 'credentials' and 'cookie' as dictionaries.
44
  """
45
+ # Load raw authentication config from secrets.toml
46
+ raw_credentials = st.secrets["auth"]["credentials"]
47
+ raw_cookie = st.secrets["auth"]["cookie"]
48
 
49
  # Parse credentials from YAML string to dict
50
  try:
51
+ credentials = yaml.safe_load(raw_credentials)
52
  except yaml.YAMLError as e:
53
  st.error(f"Error parsing credentials: {e}")
54
  return {}
55
 
56
  # Parse cookie from JSON string to dict
57
  try:
58
+ cookie = json.loads(raw_cookie)
59
  except json.JSONDecodeError as e:
60
  st.error(f"Error parsing cookie configuration: {e}")
61
  return {}
62
 
63
+ return {"credentials": credentials, "cookie": cookie}
64
 
65
  config = load_authentication()
66
 
 
82
  # -------------------------------
83
  # Define Helper Functions with Caching
84
  # -------------------------------
85
+
86
  @st.cache_data(ttl=3600)
87
  def extract_text_from_pdf(pdf_file):
88
  """
 
97
  except Exception as e:
98
  st.error(f"Error extracting text from PDF: {e}")
99
  return ""
100
+
101
  @st.cache_data(ttl=3600)
102
  def extract_job_description(job_link):
103
  """
 
116
  except Exception as e:
117
  st.error(f"Error fetching job description: {e}")
118
  return ""
119
+
120
  @st.cache_data(ttl=3600)
121
  def extract_requirements(job_description):
122
  """
 
139
  except Exception as e:
140
  st.error(f"Error extracting requirements: {e}")
141
  return ""
142
+
143
  @st.cache_data(ttl=3600)
144
  def generate_email(job_description, requirements, resume_text):
145
  """
 
173
  except Exception as e:
174
  st.error(f"Error generating email: {e}")
175
  return ""
176
+
177
  @st.cache_data(ttl=3600)
178
  def generate_cover_letter(job_description, requirements, resume_text):
179
  """
 
211
  except Exception as e:
212
  st.error(f"Error generating cover letter: {e}")
213
  return ""
214
+
215
  @st.cache_data(ttl=3600)
216
  def extract_skills(text):
217
  """
 
235
  except Exception as e:
236
  st.error(f"Error extracting skills: {e}")
237
  return []
238
+
239
  @st.cache_data(ttl=3600)
240
  def suggest_keywords(resume_text, job_description=None):
241
  """
 
261
  except Exception as e:
262
  st.error(f"Error suggesting keywords: {e}")
263
  return []
264
+
265
  @st.cache_data(ttl=3600)
266
  def get_job_recommendations(job_title, location="India"):
267
  """
 
304
  except Exception as err:
305
  st.error(f"An error occurred: {err}")
306
  return {}
307
+
308
  def create_skill_distribution_chart(skills):
309
  """
310
  Creates a bar chart showing the distribution of skills.
 
315
  df = pd.DataFrame(list(skill_counts.items()), columns=['Skill', 'Count'])
316
  fig = px.bar(df, x='Skill', y='Count', title='Skill Distribution')
317
  return fig
318
+
319
  def create_experience_timeline(resume_text):
320
  """
321
  Creates an experience timeline from the resume text.
 
358
  except Exception as e:
359
  st.error(f"Error creating experience timeline: {e}")
360
  return None
361
+
362
  def parse_duration(duration_str):
363
  """
364
  Parses duration strings like '2 years' or '6 months' into float years.
 
374
  return 0
375
  except:
376
  return 0
377
+
378
  # -------------------------------
379
  # Database Functions
380
  # -------------------------------
 
483
  except Exception as e:
484
  st.error(f"Error generating learning path: {e}")
485
  return ""
486
+
487
  # -------------------------------
488
  # Page Functions
489
  # -------------------------------
 
1205
  elif selected == "Help":
1206
  help_page()
1207
 
 
1208
 
1209
  if __name__ == "__main__":
1210
  main_app()
 
1212
  elif authentication_status == False:
1213
  st.error('Username/password is incorrect')
1214
  elif authentication_status == None:
1215
+ st.warning('Please enter your username and password')