bangaboy commited on
Commit
28843bf
·
verified ·
1 Parent(s): 60935a2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +29 -3
src/streamlit_app.py CHANGED
@@ -9,6 +9,7 @@ from datetime import datetime
9
  import re
10
  import pytesseract
11
  import io
 
12
 
13
  def extract_text_from_pdf(pdf_file):
14
  """Extract text from uploaded PDF file."""
@@ -182,16 +183,41 @@ def format_education(edu):
182
  parts.append(f"- GPA: {edu['gpa']}")
183
  return " ".join(parts)
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  def main():
186
  st.title("Resume Parser")
187
  st.write("Upload a resume (PDF, DOCX, or Image) to extract information")
188
 
189
- # Get API key from secrets or user input
190
- api_key = st.secrets["GEMINI_API_KEY"] if "GEMINI_API_KEY" in st.secrets else st.text_input("Enter Gemini API Key", type="password")
 
 
 
 
 
 
 
 
191
 
192
  uploaded_file = st.file_uploader("Choose a resume file", type=["pdf", "docx", "doc", "jpg", "jpeg", "png"])
193
 
194
- if uploaded_file and api_key:
195
  with st.spinner('Analyzing resume...'):
196
  result = parse_resume(uploaded_file, api_key)
197
 
 
9
  import re
10
  import pytesseract
11
  import io
12
+ import os
13
 
14
  def extract_text_from_pdf(pdf_file):
15
  """Extract text from uploaded PDF file."""
 
183
  parts.append(f"- GPA: {edu['gpa']}")
184
  return " ".join(parts)
185
 
186
+ def get_api_key():
187
+ """Get API key from multiple sources."""
188
+ # Try environment variable first (Hugging Face Spaces)
189
+ api_key = os.getenv("GEMINI_API_KEY")
190
+ if api_key:
191
+ return api_key
192
+
193
+ # Try Streamlit secrets (local development)
194
+ try:
195
+ if hasattr(st, 'secrets') and "GEMINI_API_KEY" in st.secrets:
196
+ return st.secrets["GEMINI_API_KEY"]
197
+ except:
198
+ pass
199
+
200
+ # Return None if not found
201
+ return None
202
+
203
  def main():
204
  st.title("Resume Parser")
205
  st.write("Upload a resume (PDF, DOCX, or Image) to extract information")
206
 
207
+ # Get API key from multiple sources
208
+ api_key = get_api_key()
209
+
210
+ # If no API key found, ask user to input
211
+ if not api_key:
212
+ api_key = st.text_input("Enter Gemini API Key", type="password")
213
+ if not api_key:
214
+ st.warning("Please enter your Gemini API Key to proceed.")
215
+ st.info("You can get your API key from: https://makersuite.google.com/app/apikey")
216
+ return
217
 
218
  uploaded_file = st.file_uploader("Choose a resume file", type=["pdf", "docx", "doc", "jpg", "jpeg", "png"])
219
 
220
+ if uploaded_file:
221
  with st.spinner('Analyzing resume...'):
222
  result = parse_resume(uploaded_file, api_key)
223