AjulorC commited on
Commit
30509f5
β€’
1 Parent(s): 6533bfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -1,9 +1,22 @@
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,11 +27,13 @@ qst_1 = "what is christian's profession?"
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(inline=False)
1
  import tensorflow as tf
2
+
3
+ #!pip install transformers
4
+
5
  from transformers import pipeline
 
6
 
7
+ # importing necessary libraries
8
+ from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering
9
+
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
12
+ model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False)
13
+
14
+ nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
15
+
16
+ #!pip install gradio
17
  import gradio as gr
18
 
19
+ # creating the function
20
  def func(context, question):
21
  result = nlp(question = question, context=context)
22
  return result['answer']
27
  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."
28
  qst_2 = "What is NLP used for?"
29
 
30
+ # creating the interface
31
  app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox',
32
  title = 'Question Answering bot', theme = 'dark-grass',
33
  description = 'Input context and question, then get answers!',
34
  examples = [[example_1, qst_1],
35
  [example_2, qst_2]]
36
  )
37
+
38
+ # launching the app
39
  app.launch(inline=False)