AjulorC commited on
Commit
ebc56ac
Β·
1 Parent(s): 1635799

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
11
+ model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False)
12
+
13
+ nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
14
+
15
+ import gradio as gr
16
+
17
+ # creating the function
18
+ def func(context, question):
19
+ result = nlp(question = question, context=context)
20
+ return result['answer']
21
+
22
+ example_1 = "(1) My name is Ajulor Christian, I am a data scientist and machine learning engineer"
23
+ qst_1 = "what is christian's profession?"
24
+
25
+ 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."
26
+ qst_2 = "What is NLP used for?"
27
+
28
+ # creating the interface
29
+ app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox',
30
+ title = 'Question Answering bot', theme = 'dark-grass',
31
+ description = 'Input context and question, then get answers!',
32
+ examples = [[example_1, qst_1],
33
+ [example_2, qst_2]]
34
+ )
35
+
36
+ # launching the app
37
+ app.launch(share=True, inline=False)