vincentclaes commited on
Commit
a226e89
1 Parent(s): 6876e6c

make qa work

Browse files
Files changed (2) hide show
  1. app.py +9 -3
  2. requirements.txt +1 -0
app.py CHANGED
@@ -3,9 +3,15 @@ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
3
  title = "Vacancy Keyword Extraction"
4
  description = "Add a vacancy and ask what keyword you would like to retrieve. For example, What is the job title? What is the city? What is the start date?"
5
 
6
- gr.Interface.load("huggingface/deepset/roberta-base-squad2",
 
 
 
 
 
 
 
7
  inputs=[gr.inputs.Textbox(lines=10, label="Vacancy", placeholder="Paste the context of a vacancy."),
8
  gr.inputs.Textbox(lines=2, label="Question", placeholder="Ask what you want to retrieve from the vacancy.")],
9
- outputs=[gr.outputs.Textbox(label="Answer"),
10
- gr.outputs.Label(label="Probability")],
11
  title=title, description=description).launch(share=False)
 
3
  title = "Vacancy Keyword Extraction"
4
  description = "Add a vacancy and ask what keyword you would like to retrieve. For example, What is the job title? What is the city? What is the start date?"
5
 
6
+
7
+ classifier = pipeline("question-answering", model="deepset/roberta-base-squad2", model_max_length=512)
8
+
9
+ def zeroShotClassification(text_input, question):
10
+ prediction = classifier(context=text_input, question=question, truncation=True, max_length="max_length", padding=True)
11
+ return f'{prediction["answer"]}'
12
+
13
+ gr.Interface(fn=zeroShotClassification,
14
  inputs=[gr.inputs.Textbox(lines=10, label="Vacancy", placeholder="Paste the context of a vacancy."),
15
  gr.inputs.Textbox(lines=2, label="Question", placeholder="Ask what you want to retrieve from the vacancy.")],
16
+ outputs=gr.outputs.Textbox(label="Answer"),
 
17
  title=title, description=description).launch(share=False)
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  transformers
2
  gradio
 
 
1
  transformers
2
  gradio
3
+ torch