hzsushiqiren commited on
Commit
93fbe7f
·
1 Parent(s): 09e9996

Upload bert-finetuned.py

Browse files
Files changed (1) hide show
  1. bert-finetuned.py +29 -0
bert-finetuned.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import (
2
+ pipeline,
3
+ AutoModelForQuestionAnswering,
4
+ AutoTokenizer,
5
+ )
6
+ import gradio as gr
7
+
8
+ # set up model name
9
+ model_name = "hzsushiqiren/bert-finetuned-squad"
10
+
11
+ #set up model to run
12
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
13
+
14
+ #set up tokenizer
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+
17
+ #set up pipeline
18
+ nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
19
+
20
+ # creating the function
21
+ def func(context, question):
22
+ result = nlp(question = question, context = context)
23
+ return result['answer']
24
+
25
+ # creating the interface
26
+ app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox', title = 'Swinburne Online FAQs Answering bot', theme = 'dark-grass', description = 'Input context and question, then get answers!')
27
+
28
+ # launching the app
29
+ app.launch(inline=False, share=True)