Spaces:
Runtime error
Runtime error
abdalrahmanshahrour
commited on
Commit
·
6acc00e
1
Parent(s):
a4ded9c
Update
Browse files
app.py
CHANGED
@@ -1,3 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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']
|
23 |
+
|
24 |
+
example_1 = "(1) My name is Abdalrahman Shahrour, I am a data scientist and AI engineer"
|
25 |
+
qst_1 = "what is shahrour's profession?"
|
26 |
+
|
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)
|