fuhsiao commited on
Commit
dfcc660
·
1 Parent(s): 47aa919
app.py CHANGED
@@ -2,6 +2,32 @@ from utils import *
2
  import gradio as gr
3
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def main(file, ext_threshold, article_type):
6
 
7
  if file is None or ext_threshold is None or article_type is None:
@@ -20,9 +46,9 @@ def main(file, ext_threshold, article_type):
20
 
21
  abstr_model_path = ''
22
  if article_type == 'non-specialized field':
23
- abstr_model_path = 'model/BART-PMC-EXT-Section'
24
  elif article_type == 'biomedical field':
25
- abstr_model_path = 'model/BioBART-PMC-EXT-Section'
26
 
27
  TOKENIZER, ABSTRMODEL = load_AbstrModel(abstr_model_path)
28
  abstr = abstractive_method(ext, tokenizer=TOKENIZER, model=ABSTRMODEL)
@@ -36,6 +62,9 @@ def main(file, ext_threshold, article_type):
36
 
37
  if __name__ == '__main__':
38
 
 
 
 
39
  # 定義Gradio介面
40
  iface = gr.Interface(
41
  fn=main,
 
2
  import gradio as gr
3
 
4
 
5
+ from transformers import PreTrainedModel, PreTrainedTokenizer, AutoTokenizer, AutoModelForSeq2SeqLM, AutoModel
6
+
7
+ def download_model():
8
+ # 下載並快取SentenceTransformer所需的模型和tokenizer
9
+ sentence_transformer_model = "sentence-transformers/all-MiniLM-L6-v2"
10
+ PreTrainedModel.from_pretrained(sentence_transformer_model)
11
+ PreTrainedTokenizer.from_pretrained(sentence_transformer_model)
12
+
13
+ # 下載並快取AutoTokenizer所需的模型
14
+ biobart_model = "fuhsiao/BioBART-PMC-EXT-Section"
15
+ PreTrainedModel.from_pretrained(biobart_model)
16
+ AutoTokenizer.from_pretrained(biobart_model)
17
+ AutoModel.from_pretrained(biobart_model)
18
+
19
+ # 下載並快取AutoModelForSeq2SeqLM所需的模型
20
+ bart_model = "fuhsiao/BART-PMC-EXT-Section"
21
+ PreTrainedModel.from_pretrained(bart_model)
22
+ AutoTokenizer.from_pretrained(bart_model)
23
+ AutoModelForSeq2SeqLM.from_pretrained(bart_model)
24
+
25
+ return True
26
+
27
+
28
+
29
+
30
+
31
  def main(file, ext_threshold, article_type):
32
 
33
  if file is None or ext_threshold is None or article_type is None:
 
46
 
47
  abstr_model_path = ''
48
  if article_type == 'non-specialized field':
49
+ abstr_model_path = 'fuhsiao/BART-PMC-EXT-Section'
50
  elif article_type == 'biomedical field':
51
+ abstr_model_path = 'fuhsiao/BioBART-PMC-EXT-Section'
52
 
53
  TOKENIZER, ABSTRMODEL = load_AbstrModel(abstr_model_path)
54
  abstr = abstractive_method(ext, tokenizer=TOKENIZER, model=ABSTRMODEL)
 
62
 
63
  if __name__ == '__main__':
64
 
65
+ download_model()
66
+
67
+
68
  # 定義Gradio介面
69
  iface = gr.Interface(
70
  fn=main,
utils/__pycache__/__init__.cpython-38.pyc ADDED
Binary file (467 Bytes). View file
 
utils/__pycache__/preprocess.cpython-38.pyc ADDED
Binary file (6.94 kB). View file
 
utils/preprocess.py CHANGED
@@ -143,7 +143,7 @@ def similarity(lst, ptm):
143
  def feature_extraction(title, section, sents):
144
  lst = sent_lst(sents)
145
  tfisf = Tfisf(lst)
146
- cosine = similarity(lst, "model/all-MiniLM-L6-v2")
147
 
148
  # Number of sentences
149
  ns = len(sents)
 
143
  def feature_extraction(title, section, sents):
144
  lst = sent_lst(sents)
145
  tfisf = Tfisf(lst)
146
+ cosine = similarity(lst, "sentence-transformers/all-MiniLM-L6-v2")
147
 
148
  # Number of sentences
149
  ns = len(sents)