Aitor commited on
Commit
f4cb80a
·
1 Parent(s): bf6416a

Formatting code

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -6,6 +6,7 @@ from langchain.document_loaders import PDFMinerLoader
6
  from langchain.indexes import VectorstoreIndexCreator
7
  import os
8
 
 
9
  def set_openai_key(raw_key):
10
  logging.warning(raw_key)
11
  os.environ["OPENAI_API_KEY"] = raw_key
@@ -30,7 +31,8 @@ def create_langchain(pdf_object):
30
  def ask_question(chain, question_text):
31
  logging.info(type(chain))
32
  return chain({"question": question_text})["result"]
33
-
 
34
  def create_ask(pdf_object, question_text):
35
  loader = PDFMinerLoader(pdf_object.name)
36
  index_creator = VectorstoreIndexCreator()
@@ -48,18 +50,30 @@ def create_ask(pdf_object, question_text):
48
 
49
  with gr.Blocks() as demo:
50
  # pdf_button = gr.Button(value="pdf_button")
51
- oai_token = gr.Textbox(label="OpenAI Token", placeholder="Lm-iIas452gaw3erGtPar26gERGSA5RVkFJQST23WEG524EWEl")
 
 
 
52
  oai_token.change(set_openai_key, oai_token)
53
  pdf_object = gr.File(
54
- label="Upload your CV in PDF format",
55
- file_count="single",
56
- type="file")
57
  chain_state = gr.State()
58
- # pdf_button.click(create_langchain, inputs=pdf_object, outputs=chain_state)
59
- question_box = gr.Textbox(label="Question", value="Which are the candidate top hard skills? Enumerate in few bullet points.")
 
 
 
 
60
  qa_button = gr.Button(value="Submit question", interactive=False)
61
 
62
- lchain = pdf_object.change(create_langchain, inputs=pdf_object, outputs=[chain_state, qa_button])
63
- qa_button.click(ask_question, inputs=[chain_state, question_box], outputs=gr.Textbox(label="Answer"))
 
 
 
 
 
 
64
 
65
- demo.launch(debug=True)
 
6
  from langchain.indexes import VectorstoreIndexCreator
7
  import os
8
 
9
+
10
  def set_openai_key(raw_key):
11
  logging.warning(raw_key)
12
  os.environ["OPENAI_API_KEY"] = raw_key
 
31
  def ask_question(chain, question_text):
32
  logging.info(type(chain))
33
  return chain({"question": question_text})["result"]
34
+
35
+
36
  def create_ask(pdf_object, question_text):
37
  loader = PDFMinerLoader(pdf_object.name)
38
  index_creator = VectorstoreIndexCreator()
 
50
 
51
  with gr.Blocks() as demo:
52
  # pdf_button = gr.Button(value="pdf_button")
53
+ oai_token = gr.Textbox(
54
+ label="OpenAI Token",
55
+ placeholder="Lm-iIas452gaw3erGtPar26gERGSA5RVkFJQST23WEG524EWEl",
56
+ )
57
  oai_token.change(set_openai_key, oai_token)
58
  pdf_object = gr.File(
59
+ label="Upload your CV in PDF format", file_count="single", type="file"
60
+ )
 
61
  chain_state = gr.State()
62
+ question_placeholder = """
63
+ Enumerate the candidate's top 5 hard skills and rate them by importance from 0 to 5.
64
+ Example:
65
+ - Algebra 5/5
66
+ """
67
+ question_box = gr.Textbox(label="Question", value=question_placeholder)
68
  qa_button = gr.Button(value="Submit question", interactive=False)
69
 
70
+ lchain = pdf_object.change(
71
+ create_langchain, inputs=pdf_object, outputs=[chain_state, qa_button]
72
+ )
73
+ qa_button.click(
74
+ ask_question,
75
+ inputs=[chain_state, question_box],
76
+ outputs=gr.Textbox(label="Answer"),
77
+ )
78
 
79
+ demo.launch(debug=True)