Spaces:
Runtime error
Runtime error
littlehousezh
commited on
Commit
•
6f9ea8e
1
Parent(s):
5e9e309
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Job-coach-document-testing-site.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1ECyP45v5tfkn0I-0W24qWGQotWyqPIQS
|
8 |
+
"""
|
9 |
+
|
10 |
+
! pip install gradio
|
11 |
+
! pip install transformers
|
12 |
+
import gradio as gr
|
13 |
+
|
14 |
+
import torch
|
15 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
|
16 |
+
from transformers import pipeline
|
17 |
+
|
18 |
+
def QA_function(context, queries):
|
19 |
+
#tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
|
20 |
+
|
21 |
+
model = "bert-large-uncased-whole-word-masking-finetuned-squad"
|
22 |
+
|
23 |
+
question_answerer = pipeline("question-answering", model = model)
|
24 |
+
Answered=[]
|
25 |
+
NotAnswered=[]
|
26 |
+
queries=queries.split("?")
|
27 |
+
queries.pop(-1)
|
28 |
+
for query in queries:
|
29 |
+
query.strip()
|
30 |
+
result = question_answerer(question = query, context=context)
|
31 |
+
if result['score'] > 0.01:
|
32 |
+
Answered.append(query +"? Answer: " + result['answer'])
|
33 |
+
else:
|
34 |
+
NotAnswered.append(query)
|
35 |
+
|
36 |
+
#print("Question Answered: ")
|
37 |
+
#for answer in Answered:
|
38 |
+
#print(answer)
|
39 |
+
# print("Question Not Answered: ")
|
40 |
+
# for answer in NotAnswered:
|
41 |
+
# print(answer)
|
42 |
+
result1=''',
|
43 |
+
'''.join(Answered)
|
44 |
+
result1='''Question Answered:
|
45 |
+
'''+ result1
|
46 |
+
result2=''',
|
47 |
+
'''.join(NotAnswered)
|
48 |
+
result2='''
|
49 |
+
Question Not Answered:
|
50 |
+
'''+ result2
|
51 |
+
|
52 |
+
return result1 + result2
|
53 |
+
|
54 |
+
title = "Testing demo"
|
55 |
+
description = "A testing site for Job Coach Documents"
|
56 |
+
|
57 |
+
gradio_ui = gr.Interface(QA_function, [gr.inputs.Textbox(lines=10, label="Context"), gr.inputs.Textbox(lines=10, label="Question")], gr.outputs.Textbox(label="Answer"))
|
58 |
+
gradio_ui.launch(debug=True)
|