Sujithanumala commited on
Commit
acdfc27
·
verified ·
1 Parent(s): fd1094b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import gradio as gr
2
  from pypdf import PdfReader
3
  from resume_tools import create_resume_agent
4
-
 
5
 
6
  def read_pdf_file(file_path):
7
  """
@@ -24,7 +25,28 @@ def read_pdf_file(file_path):
24
 
25
 
26
 
27
- def process_inputs(resume, job_description, custom_instructions):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  if resume is not None:
29
  resume = read_pdf_file(resume)
30
  else:
@@ -131,7 +153,7 @@ def process_inputs(resume, job_description, custom_instructions):
131
  Do not generate final resume at once — output tool-wise only.
132
  """
133
 
134
- print(prompt)
135
  return create_resume_agent(prompt)
136
 
137
  with gr.Blocks() as demo:
@@ -141,12 +163,13 @@ with gr.Blocks() as demo:
141
  resume = gr.File(label="Upload Resume", file_types=[".pdf"])
142
  job_description = gr.Textbox(label="Paste Job Description here", lines=5)
143
  custom_instructions = gr.Textbox(label="Just Instruct how you want it to be......!!!!", lines=5)
 
144
  submit_btn = gr.Button("Submit")
145
  with gr.Column():
146
  output = gr.Textbox(label="LaTEX Resume File", lines=10)
147
  submit_btn.click(
148
  fn=process_inputs,
149
- inputs=[resume, job_description,custom_instructions],
150
  outputs=output
151
  )
152
 
 
1
  import gradio as gr
2
  from pypdf import PdfReader
3
  from resume_tools import create_resume_agent
4
+ import google.generativeai as genai
5
+ import os
6
 
7
  def read_pdf_file(file_path):
8
  """
 
25
 
26
 
27
 
28
+ def verify_gemini_api_key(api_key):
29
+ try:
30
+ genai.configure(api_key=api_key)
31
+ models = genai.list_models()
32
+ for model in models:
33
+ pass
34
+ return True,""
35
+ except Exception as e:
36
+ if "API key not valid" in str(e) or "PERMISSION_DENIED" in str(e):
37
+ return False,"Reason: The API key itself is likely incorrect or lacks necessary permissions."
38
+ elif "FAILED_PRECONDITION" in str(e) and "free tier is not available" in str(e):
39
+ return False,"Reason: Free tier might not be available in your region, or billing needs to be enabled."
40
+ elif "RESOURCE_EXHAUSTED" in str(e):
41
+ return False,"Reason: Rate limit exceeded or quota exhausted for this API key."
42
+ return False,""
43
+
44
+
45
+ def process_inputs(resume, job_description, custom_instructions,gemini_api_key):
46
+ response,code = verify_gemini_api_key(gemini_api_key)
47
+ if not response:
48
+ return code
49
+ os.environ["GOOGLE_API_KEY"] = gemini_api_key
50
  if resume is not None:
51
  resume = read_pdf_file(resume)
52
  else:
 
153
  Do not generate final resume at once — output tool-wise only.
154
  """
155
 
156
+ # print(prompt)
157
  return create_resume_agent(prompt)
158
 
159
  with gr.Blocks() as demo:
 
163
  resume = gr.File(label="Upload Resume", file_types=[".pdf"])
164
  job_description = gr.Textbox(label="Paste Job Description here", lines=5)
165
  custom_instructions = gr.Textbox(label="Just Instruct how you want it to be......!!!!", lines=5)
166
+ gemini_api_key = gr.Textbox(label="Enter your Gemini API key..!!! Don't worry we wont store it. You can get it from https://aistudio.google.com/app/apikey", lines=1)
167
  submit_btn = gr.Button("Submit")
168
  with gr.Column():
169
  output = gr.Textbox(label="LaTEX Resume File", lines=10)
170
  submit_btn.click(
171
  fn=process_inputs,
172
+ inputs=[resume, job_description,custom_instructions,gemini_api_key],
173
  outputs=output
174
  )
175