Working with examples
Browse files- Add Aitor CV as sample data
- Add button to explicitly create langchain
- Fix placeholder text
- app.py +20 -13
- sample_data/CV_AITOR_MIRA.pdf +0 -0
app.py
CHANGED
@@ -14,10 +14,9 @@ def set_openai_key(raw_key):
|
|
14 |
response = requests.get("https://api.openai.com/v1/engines", headers=headers)
|
15 |
if response.status_code != 200:
|
16 |
raise gr.Error("API key is not valid. Check the key and try again.")
|
17 |
-
|
18 |
os.environ["OPENAI_API_KEY"] = raw_key
|
19 |
-
|
20 |
-
return gr.File.update(interactive=True)
|
21 |
|
22 |
|
23 |
def create_langchain(pdf_object):
|
@@ -40,6 +39,9 @@ def ask_question(chain, question_text):
|
|
40 |
|
41 |
|
42 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
43 |
# Layout
|
44 |
oai_token = gr.Textbox(
|
45 |
label="OpenAI Token",
|
@@ -52,21 +54,26 @@ with gr.Blocks() as demo:
|
|
52 |
type="file",
|
53 |
interactive=False,
|
54 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
question_placeholder = """
|
57 |
-
|
58 |
-
|
59 |
-
- Algebra 5/5
|
60 |
-
"""
|
61 |
question_box = gr.Textbox(label="Question", value=question_placeholder)
|
62 |
qa_button = gr.Button(value="Submit question", interactive=False)
|
63 |
|
64 |
-
# Sate objects
|
65 |
-
chain_state = gr.State()
|
66 |
-
|
67 |
# Actions
|
68 |
-
oai_token.change(
|
69 |
-
|
|
|
|
|
70 |
create_langchain, inputs=pdf_object, outputs=[chain_state, qa_button]
|
71 |
)
|
72 |
qa_button.click(
|
|
|
14 |
response = requests.get("https://api.openai.com/v1/engines", headers=headers)
|
15 |
if response.status_code != 200:
|
16 |
raise gr.Error("API key is not valid. Check the key and try again.")
|
17 |
+
|
18 |
os.environ["OPENAI_API_KEY"] = raw_key
|
19 |
+
return gr.File.update(interactive=True), gr.Button.update(interactive=True)
|
|
|
20 |
|
21 |
|
22 |
def create_langchain(pdf_object):
|
|
|
39 |
|
40 |
|
41 |
with gr.Blocks() as demo:
|
42 |
+
# Sate objects
|
43 |
+
chain_state = gr.State()
|
44 |
+
|
45 |
# Layout
|
46 |
oai_token = gr.Textbox(
|
47 |
label="OpenAI Token",
|
|
|
54 |
type="file",
|
55 |
interactive=False,
|
56 |
)
|
57 |
+
gr.Examples(
|
58 |
+
examples=[
|
59 |
+
os.path.join(os.path.abspath(""), "sample_data", "CV_AITOR_MIRA.pdf")
|
60 |
+
],
|
61 |
+
inputs=pdf_object,
|
62 |
+
label="Example CV",
|
63 |
+
)
|
64 |
+
create_chain_btn = gr.Button(value="Create CVchat", interactive=False)
|
65 |
|
66 |
+
question_placeholder = """Enumerate the candidate's top 5 hard skills and rate them by importance from 0 to 5.
|
67 |
+
Example:
|
68 |
+
- Algebra 5/5"""
|
|
|
|
|
69 |
question_box = gr.Textbox(label="Question", value=question_placeholder)
|
70 |
qa_button = gr.Button(value="Submit question", interactive=False)
|
71 |
|
|
|
|
|
|
|
72 |
# Actions
|
73 |
+
oai_token.change(
|
74 |
+
set_openai_key, inputs=oai_token, outputs=[pdf_object, create_chain_btn]
|
75 |
+
)
|
76 |
+
lchain = create_chain_btn.click(
|
77 |
create_langchain, inputs=pdf_object, outputs=[chain_state, qa_button]
|
78 |
)
|
79 |
qa_button.click(
|
sample_data/CV_AITOR_MIRA.pdf
ADDED
The diff for this file is too large to render.
See raw diff
|
|