hema1 commited on
Commit
005eefa
·
1 Parent(s): a461080

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import gradio as gr
3
+ # importing necessary libraries
4
+ from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering
5
+
6
+ tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
7
+ model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False)
8
+ from transformers import pipeline
9
+
10
+ nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
11
+
12
+ context = "My name is Ajulor Christian, i am a data scientist and machine learning engineer"
13
+ question = "what is my profession?"
14
+
15
+ result = nlp(question = question, context=context)
16
+
17
+ print(f"QUESTION: {question}")
18
+ print(f"ANSWER: {result['answer']}")
19
+
20
+ # creating the function
21
+ def func(context, question):
22
+ result = nlp(question = question, context=context)
23
+ return result['answer']
24
+
25
+ example_1 = "(1) My name is Ajulor Christian, I am a data scientist and machine learning engineer"
26
+ qst_1 = "what is christian's profession?"
27
+
28
+ 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."
29
+ qst_2 = "What is NLP used for?"
30
+
31
+ # creating the interface
32
+ app = gr.Interface(fn=func,
33
+ inputs = ['textbox', 'text'],
34
+ outputs = gr.Textbox( lines=10),
35
+ title = 'Question Answering bot',
36
+ description = 'Input context and question, then get answers!',
37
+ examples = [[example_1, qst_1],
38
+ [example_2, qst_2]],
39
+ theme = "darkhuggingface",
40
+ Timeout =120,
41
+ flagging_options=["incorrect", "ambiguous", "offensive", "other"],
42
+
43
+ ).queue()
44
+ # launching the app
45
+ app.launch(auth = ('user','saitmhema'), auth_message = "Check your Login details sent to your email")