mehdirabiee commited on
Commit
33290c4
·
1 Parent(s): 5e45ce5

gradio blocks

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -11,11 +11,38 @@ def parse_resume(pdf, use_openai=False, openai_key=""):
11
  resume = resume.model_dump_json()
12
  return resume
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  demo = gr.Interface(
15
  fn=parse_resume,
16
  inputs=[PDF(label="Upload a PDF", interactive=True), gr.Checkbox(label="Use OpenAI"), gr.Text(label="OpenAI Token")],
17
  outputs=[gr.JSON()],
18
  examples=[[f"samples/{fname}"] for fname in os.listdir("samples") if fname.endswith(".pdf")]
19
  )
 
20
 
21
  demo.launch()
 
11
  resume = resume.model_dump_json()
12
  return resume
13
 
14
+ def change_openai_checkbox(openai_key):
15
+ if len(openai_key) > 0 or "OPENAI_API_KEY" in os.environ:
16
+ return gr.Checkbox(label="Use OpenAI", interactive=True)
17
+ else:
18
+ return gr.Checkbox(label="Use OpenAI", interactive=False, value=False)
19
+
20
+
21
+ with gr.Blocks() as demo:
22
+ with gr.Row():
23
+ with gr.Column():
24
+ pdf_file_txt = PDF(label="Upload a Resume (pdf)", interactive=True)
25
+ use_openai_chk = gr.Checkbox(label="Use OpenAI")
26
+ openai_key_txt = gr.Text(label="OpenAI Token")
27
+ with gr.Row():
28
+ parse_btn = gr.Button("Parse Resume")
29
+ clear_btn = gr.ClearButton(components=[pdf_file_txt, use_openai_chk, openai_key_txt])
30
+ with gr.Column():
31
+ out_txt = gr.JSON(label="Structured Output")
32
+ examples = gr.Examples(examples=[[f"samples/{fname}"] for fname in os.listdir("samples") if fname.endswith(".pdf")],
33
+ inputs=[pdf_file_txt])
34
+ openai_key_txt.change(change_openai_checkbox, inputs=openai_key_txt, outputs=use_openai_chk)
35
+ parse_btn.click(parse_resume, inputs=[pdf_file_txt, use_openai_chk, openai_key_txt], outputs=[out_txt])
36
+ openai_key_txt.value = ""
37
+
38
+
39
+ '''
40
  demo = gr.Interface(
41
  fn=parse_resume,
42
  inputs=[PDF(label="Upload a PDF", interactive=True), gr.Checkbox(label="Use OpenAI"), gr.Text(label="OpenAI Token")],
43
  outputs=[gr.JSON()],
44
  examples=[[f"samples/{fname}"] for fname in os.listdir("samples") if fname.endswith(".pdf")]
45
  )
46
+ '''
47
 
48
  demo.launch()