DrDavis commited on
Commit
e80d1a5
·
1 Parent(s): 29f1c2a

Adding gradio interface

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -1,7 +1,28 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
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()