barghavani commited on
Commit
07972f6
·
verified ·
1 Parent(s): 4235c40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -36
app.py CHANGED
@@ -2,12 +2,16 @@ import gradio as gr
2
  import os
3
  import io
4
  import PyPDF2
 
5
  from langchain_openai import ChatOpenAI
 
6
  from langchain.chains import LLMChain
7
  from langchain.memory import ConversationBufferMemory
8
  from langchain import PromptTemplate
9
 
10
- from gradio.components import File, Textbox, Slider
 
 
11
 
12
  def extract_text_from_pdf_binary(pdf_binary):
13
  text = ""
@@ -23,11 +27,14 @@ def extract_text_from_pdf_binary(pdf_binary):
23
  return text
24
 
25
  def format_resume_to_yaml(api_key, file_content):
 
26
  os.environ['OPENAI_API_KEY'] = api_key
27
 
 
28
  if not file_content:
29
  raise ValueError("The uploaded file is empty.")
30
 
 
31
  resume_text = extract_text_from_pdf_binary(file_content)
32
 
33
  template = """Format the provided resume to this YAML template:
@@ -82,30 +89,12 @@ def format_resume_to_yaml(api_key, file_content):
82
  res = llm_chain.predict(human_input=resume_text)
83
  return res
84
 
85
- def match_resume_to_job_description(api_key, resume_file_content, job_description):
86
- os.environ['OPENAI_API_KEY'] = api_key
87
-
88
- if not resume_file_content or not job_description:
89
- raise ValueError("The uploaded file or job description is empty.")
90
-
91
- resume_text = extract_text_from_pdf_binary(resume_file_content)
92
-
93
- prompt = f"Given the following resume text:\n{resume_text}\n\nAnd the job description:\n{job_description}\n\nEvaluate how well the resume matches the job description and provide a matching score from 0 to 100, where 100 is a perfect match."
94
-
95
- llm = ChatOpenAI(model="gpt-3.5-turbo")
96
- response = llm.predict(prompt=prompt)
97
-
98
- return response
99
-
100
  def main():
101
- input_api_key = gr.Textbox(label="Enter your OpenAI API Key")
102
- input_pdf_file = gr.File(label="Upload your PDF resume", type="binary")
103
- input_job_description = gr.Textbox(label="Enter the job description", placeholder="Paste the job description here")
104
- output_yaml = gr.Textbox(label="Formatted Resume in YAML")
105
- output_match_score = gr.Textbox(label="Resume Match Score")
106
-
107
- # Define separate interfaces for each function to simplify
108
- format_resume_interface = gr.Interface(
109
  fn=format_resume_to_yaml,
110
  inputs=[input_api_key, input_pdf_file],
111
  outputs=output_yaml,
@@ -113,17 +102,7 @@ def main():
113
  description="Upload a PDF resume and enter your OpenAI API key to get it formatted to a YAML template.",
114
  )
115
 
116
- match_resume_interface = gr.Interface(
117
- fn=match_resume_to_job_description,
118
- inputs=[input_api_key, input_pdf_file, input_job_description],
119
- outputs=output_match_score,
120
- title="Resume Matcher",
121
- description="Upload a PDF resume, enter your OpenAI API key and job description to get the matching score.",
122
- )
123
-
124
- # Launch interfaces in parallel if needed, or redesign to choose which to display based on user input
125
- format_resume_interface.launch(debug=True, share=True)
126
- # match_resume_interface.launch(debug=True, share=True) # Uncomment to run separately
127
 
128
  if __name__ == "__main__":
129
- main()
 
2
  import os
3
  import io
4
  import PyPDF2
5
+ #from langchain.llms import OpenAIChat
6
  from langchain_openai import ChatOpenAI
7
+
8
  from langchain.chains import LLMChain
9
  from langchain.memory import ConversationBufferMemory
10
  from langchain import PromptTemplate
11
 
12
+
13
+ # Updated imports for Gradio components
14
+ from gradio.components import File, Textbox
15
 
16
  def extract_text_from_pdf_binary(pdf_binary):
17
  text = ""
 
27
  return text
28
 
29
  def format_resume_to_yaml(api_key, file_content):
30
+ # Set the API key for OpenAI
31
  os.environ['OPENAI_API_KEY'] = api_key
32
 
33
+ # Check if the file content is not empty
34
  if not file_content:
35
  raise ValueError("The uploaded file is empty.")
36
 
37
+ # Extract text from the uploaded PDF binary
38
  resume_text = extract_text_from_pdf_binary(file_content)
39
 
40
  template = """Format the provided resume to this YAML template:
 
89
  res = llm_chain.predict(human_input=resume_text)
90
  return res
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  def main():
93
+ input_api_key = Textbox(label="Enter your OpenAI API Key")
94
+ input_pdf_file = File(label="Upload your PDF resume", type="binary")
95
+ output_yaml = Textbox(label="Formatted Resume in YAML")
96
+
97
+ iface = gr.Interface(
 
 
 
98
  fn=format_resume_to_yaml,
99
  inputs=[input_api_key, input_pdf_file],
100
  outputs=output_yaml,
 
102
  description="Upload a PDF resume and enter your OpenAI API key to get it formatted to a YAML template.",
103
  )
104
 
105
+ iface.launch(debug=True, share=True)
 
 
 
 
 
 
 
 
 
 
106
 
107
  if __name__ == "__main__":
108
+ main()