abdalrahmanshahrour's picture
update
ef8268c
import tensorflow as tf
#!pip install transformers
from transformers import pipeline
# importing necessary libraries
from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering
tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False)
nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
#!pip install gradio
import gradio as gr
# creating the function
def func(context, question):
result = nlp(question = question, context=context)
return result['answer']
example_1 = "(1) My name is Abdalrahman Shahrour, I am a data scientist and AI engineer"
qst_1 = "what is shahrour's profession?"
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."
qst_2 = "What is NLP used for?"
example_3 = "Data science continues to evolve as one of the most promising and in-demand career paths for skilled professionals. Today, successful data professionals understand that they must advance past the traditional skills of analyzing large amounts of data, data mining, and programming skills. In order to uncover useful intelligence for their organizations, data scientists must master the full spectrum of the data science life cycle and possess a level of flexibility and understanding to maximize returns at each phase of the process."
qst_3 = "What is data science"
# creating the interface
app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox',
title = 'Question Answering bot', theme = 'dark-grass',
description = 'Input context and question, then get answers!',
examples = [[example_1, qst_1],
[example_2, qst_2],
[example_3, qst_3]]
)
# launching the app
app.launch(inline=False)