Spaces:
Sleeping
Sleeping
Adding gradio interface
Browse files
app.py
CHANGED
|
@@ -1,7 +1,28 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from transformers import pipeline, AutoTokenizer, TFAutoModelForQuestionAnswering
|
| 5 |
+
|
| 6 |
+
#Option 1: Load the tokenizer and model separately
|
| 7 |
+
#tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
|
| 8 |
+
#model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad", return_dict=False)
|
| 9 |
+
|
| 10 |
+
#Option 2: Use the HuggingFace pipeline function
|
| 11 |
+
nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
| 12 |
|
| 13 |
+
def func(context, question):
|
| 14 |
+
result = nlp(question=question, context=context)
|
| 15 |
+
return result['answer']
|
| 16 |
|
| 17 |
+
app = gr.Interface(fn=func,
|
| 18 |
+
inputs = ['textbox', 'text'],
|
| 19 |
+
outputs = gr.Textbox(lines=10),
|
| 20 |
+
title = 'Question Answering Bot',
|
| 21 |
+
description = 'Input context and question, then get answers!',
|
| 22 |
+
examples = [[example_1, qst_1],
|
| 23 |
+
[example_2, qst_2]],
|
| 24 |
+
theme = "darkhuggingface",
|
| 25 |
+
timeout = 120,
|
| 26 |
+
allow_flagging="manual",
|
| 27 |
+
flagging_options=["incorrect", "ambiguous", "offensive", "other"],
|
| 28 |
+
).queue()
|