xjlulu commited on
Commit
a448356
1 Parent(s): 4c8872b
Files changed (2) hide show
  1. app.py +34 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+ from datasets import load_dataset
5
+
6
+ dataset = load_dataset("xjlulu/ntu_adl_QA", "Preprocess", split="validation")
7
+
8
+ inputs = [
9
+ gr.inputs.Textbox(lines=3, label="Question"),
10
+ gr.inputs.Textbox(lines=12, label="Context paragraph"),
11
+ ]
12
+
13
+ examples = [{"Question": data["question"], "Context paragraph": data["context"]} for data in dataset[2:6]]
14
+
15
+ model_name = "cluecorpussmall"
16
+ question_answering = pipeline("question-answering", model=f"xjlulu/ntu_adl_span_selection_{model_name}")
17
+
18
+ def generate_answer(question, context):
19
+ result = question_answering(question=question, context=context)
20
+ return result['answer']
21
+
22
+ iface = gr.Interface(
23
+ fn=generate_answer,
24
+ inputs=inputs,
25
+ outputs=gr.Textbox(lines=10, label="Answer"),
26
+ title="Question Answering",
27
+ description="Answer questions based on a given context paragraph",
28
+ live=False,
29
+ examples=examples,
30
+ share=True,
31
+ theme="huggingface"
32
+ )
33
+
34
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ text-generation==0.6.0
2
+ transformers==4.31.0
3
+ pymongo==4.4.1
4
+ torch
5
+ sentencepiece
6
+ protobuf