Spaces:
Build error
Build error
consciousAI
commited on
Commit
·
8da1878
1
Parent(s):
ab6d9a9
Update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,21 @@ def predict(query, context):
|
|
52 |
cust_answer_sentence = cust_answer_sentence[0]
|
53 |
else:
|
54 |
cust_answer_sentence = "Failed matching sentence (answer may be split in multiple sentences)"
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
#Custom2
|
57 |
cust_answer_2 = _generate(query, context, model="consciousAI/question-answering-generative-t5-v1-base-s-q-c", device=device)
|
58 |
cust_answer_sentence_2 = [_sent for _sent in sent_tokenize(context) if cust_answer_2 in _sent]
|
@@ -62,7 +76,7 @@ def predict(query, context):
|
|
62 |
cust_answer_sentence_2 = "Failed matching sentence (answer may be split in multiple sentences)"
|
63 |
cust_answer_span_2 = re.search(cust_answer_2, contextDefault).span()
|
64 |
|
65 |
-
return cust_answer, cust_answer_sentence, cust_answer_span, cust_confidence, cust_answer_2, cust_answer_sentence_2, cust_answer_span_2
|
66 |
|
67 |
with gr.Blocks() as demo:
|
68 |
gr.Markdown(value="# Question Answering Encoders vs Generative\n [Question Answering Leveraging Encoders](https://huggingface.co/anshoomehra/question-answering-roberta-base-s)\n\n[Generative Question Answering](https://huggingface.co/anshoomehra/question-answering-generative-t5-v1-base-s-q-c)")
|
@@ -78,8 +92,13 @@ with gr.Blocks() as demo:
|
|
78 |
with gr.Column(variant='compact'):
|
79 |
_predictionM6 = gr.Textbox(label="question-answering-roberta-base-s: Answer Sentence")
|
80 |
_predictionM5 = gr.Textbox(label="question-answering-roberta-base-s: Answer")
|
81 |
-
_predictionM7 = gr.Textbox(label="question-answering-roberta-base-s:
|
82 |
_predictionM8 = gr.Textbox(label="question-answering-roberta-base-s: Answer Confidence")
|
|
|
|
|
|
|
|
|
|
|
83 |
with gr.Column(variant='compact'):
|
84 |
_predictionM10 = gr.Textbox(label="question-answering-generative-t5-v1-base-s-q-c: Sentence")
|
85 |
_predictionM9 = gr.Textbox(label="question-answering-generative-t5-v1-base-s-q-c: Answer")
|
@@ -90,7 +109,7 @@ with gr.Blocks() as demo:
|
|
90 |
gen_btn = gr.Button("Generate Answers")
|
91 |
gen_btn.click(fn=predict,
|
92 |
inputs=[query, context],
|
93 |
-
outputs=[_predictionM5, _predictionM6, _predictionM7, _predictionM8, _predictionM9, _predictionM10, _predictionM11]
|
94 |
)
|
95 |
|
96 |
demo.launch(show_error=True)
|
|
|
52 |
cust_answer_sentence = cust_answer_sentence[0]
|
53 |
else:
|
54 |
cust_answer_sentence = "Failed matching sentence (answer may be split in multiple sentences)"
|
55 |
+
|
56 |
+
#Custom3
|
57 |
+
cust_model_name_3 = "consciousAI/question-answering-roberta-base-s-v2"
|
58 |
+
cust_question_answerer_3 = pipeline('question-answering', model=cust_model_name_3, tokenizer=cust_model_name_3, device=device)
|
59 |
+
|
60 |
+
cust_output_3 = cust_question_answerer_3(question=query, context=context)
|
61 |
+
cust_answer_3 = cust_output_3['answer']
|
62 |
+
cust_answer_span_3 = "[" + str(cust_output_3['start']) + "," + str(cust_output_3['end']) + "]"
|
63 |
+
cust_confidence_3 = cust_output_3['score']
|
64 |
+
cust_answer_sentence_3 = [_sent for _sent in sent_tokenize(context) if cust_answer_3 in _sent]
|
65 |
+
if len(cust_answer_sentence_3) > 0:
|
66 |
+
cust_answer_sentence_3 = cust_answer_sentence_3[0]
|
67 |
+
else:
|
68 |
+
cust_answer_sentence_3 = "Failed matching sentence (answer may be split in multiple sentences)"
|
69 |
+
|
70 |
#Custom2
|
71 |
cust_answer_2 = _generate(query, context, model="consciousAI/question-answering-generative-t5-v1-base-s-q-c", device=device)
|
72 |
cust_answer_sentence_2 = [_sent for _sent in sent_tokenize(context) if cust_answer_2 in _sent]
|
|
|
76 |
cust_answer_sentence_2 = "Failed matching sentence (answer may be split in multiple sentences)"
|
77 |
cust_answer_span_2 = re.search(cust_answer_2, contextDefault).span()
|
78 |
|
79 |
+
return cust_answer, cust_answer_sentence, cust_answer_span, cust_confidence, cust_answer_2, cust_answer_sentence_2, cust_answer_span_2, cust_answer_3, cust_answer_sentence_3, cust_answer_span_3, cust_confidence_3
|
80 |
|
81 |
with gr.Blocks() as demo:
|
82 |
gr.Markdown(value="# Question Answering Encoders vs Generative\n [Question Answering Leveraging Encoders](https://huggingface.co/anshoomehra/question-answering-roberta-base-s)\n\n[Generative Question Answering](https://huggingface.co/anshoomehra/question-answering-generative-t5-v1-base-s-q-c)")
|
|
|
92 |
with gr.Column(variant='compact'):
|
93 |
_predictionM6 = gr.Textbox(label="question-answering-roberta-base-s: Answer Sentence")
|
94 |
_predictionM5 = gr.Textbox(label="question-answering-roberta-base-s: Answer")
|
95 |
+
_predictionM7 = gr.Textbox(label="question-answering-roberta-base-s: Q&A Answer Span")
|
96 |
_predictionM8 = gr.Textbox(label="question-answering-roberta-base-s: Answer Confidence")
|
97 |
+
with gr.Column(variant='compact'):
|
98 |
+
_predictionM12 = gr.Textbox(label="question-answering-roberta-base-s-v2: Answer Sentence")
|
99 |
+
_predictionM13 = gr.Textbox(label="question-answering-roberta-base-s-v2: Answer")
|
100 |
+
_predictionM14 = gr.Textbox(label="question-answering-roberta-base-s-v2: Q&A Answer Span")
|
101 |
+
_predictionM15 = gr.Textbox(label="question-answering-roberta-base-s-v2: Answer Confidence")
|
102 |
with gr.Column(variant='compact'):
|
103 |
_predictionM10 = gr.Textbox(label="question-answering-generative-t5-v1-base-s-q-c: Sentence")
|
104 |
_predictionM9 = gr.Textbox(label="question-answering-generative-t5-v1-base-s-q-c: Answer")
|
|
|
109 |
gen_btn = gr.Button("Generate Answers")
|
110 |
gen_btn.click(fn=predict,
|
111 |
inputs=[query, context],
|
112 |
+
outputs=[_predictionM5, _predictionM6, _predictionM7, _predictionM8, _predictionM9, _predictionM10, _predictionM11, _predictionM12, _predictionM13, _predictionM14, _predictionM15]
|
113 |
)
|
114 |
|
115 |
demo.launch(show_error=True)
|