Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,9 @@
|
|
1 |
import tensorflow as tf
|
2 |
-
|
3 |
from transformers import pipeline
|
4 |
-
|
5 |
-
# importing necessary libraries
|
6 |
-
from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering
|
7 |
-
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
|
9 |
-
model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False)
|
10 |
-
|
11 |
-
nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
12 |
|
13 |
import gradio as gr
|
14 |
|
15 |
-
# creating the function
|
16 |
def func(context, question):
|
17 |
result = nlp(question = question, context=context)
|
18 |
return result['answer']
|
@@ -23,13 +14,11 @@ qst_1 = "what is christian's profession?"
|
|
23 |
example_2 = "(2) Natural Language Processing (NLP) allows machines to break down and interpret human language. It's at the core of tools we use every day β from translation software, chatbots, spam filters, and search engines, to grammar correction software, voice assistants, and social media monitoring tools."
|
24 |
qst_2 = "What is NLP used for?"
|
25 |
|
26 |
-
# creating the interface
|
27 |
app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox',
|
28 |
title = 'Question Answering bot', theme = 'dark-grass',
|
29 |
description = 'Input context and question, then get answers!',
|
30 |
examples = [[example_1, qst_1],
|
31 |
[example_2, qst_2]]
|
32 |
)
|
33 |
-
|
34 |
-
# launching the app
|
35 |
app.launch(share=True, inline=False)
|
|
|
1 |
import tensorflow as tf
|
|
|
2 |
from transformers import pipeline
|
3 |
+
nlp = pipeline("question-answering")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
|
|
|
7 |
def func(context, question):
|
8 |
result = nlp(question = question, context=context)
|
9 |
return result['answer']
|
|
|
14 |
example_2 = "(2) Natural Language Processing (NLP) allows machines to break down and interpret human language. It's at the core of tools we use every day β from translation software, chatbots, spam filters, and search engines, to grammar correction software, voice assistants, and social media monitoring tools."
|
15 |
qst_2 = "What is NLP used for?"
|
16 |
|
|
|
17 |
app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox',
|
18 |
title = 'Question Answering bot', theme = 'dark-grass',
|
19 |
description = 'Input context and question, then get answers!',
|
20 |
examples = [[example_1, qst_1],
|
21 |
[example_2, qst_2]]
|
22 |
)
|
23 |
+
|
|
|
24 |
app.launch(share=True, inline=False)
|