chinhon commited on
Commit
9967432
1 Parent(s): a8bd7b5

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -100
app.py DELETED
@@ -1,100 +0,0 @@
1
- import gradio as gr
2
- import re
3
-
4
- from gradio.mix import Parallel
5
- from transformers import (
6
- AutoTokenizer,
7
- AutoModelForSeq2SeqLM
8
- )
9
-
10
- def clean_text(text):
11
- text = text.encode("ascii", errors="ignore").decode(
12
- "ascii"
13
- ) # remove non-ascii, Chinese characters
14
- text = re.sub(r"\n", " ", text)
15
- text = re.sub(r"\n\n", " ", text)
16
- text = re.sub(r"\t", " ", text)
17
- text = text.strip(" ")
18
- text = re.sub(
19
- " +", " ", text
20
- ).strip() # get rid of multiple spaces and replace with a single
21
- return text
22
-
23
-
24
- modchoice_1 = "chinhon/bart-large-cnn-summarizer_03"
25
-
26
- def summarizer1(text):
27
- input_text = clean_text(text)
28
-
29
- tokenizer_1 = AutoTokenizer.from_pretrained(modchoice_1)
30
-
31
- model_1 = AutoModelForSeq2SeqLM.from_pretrained(modchoice_1)
32
-
33
- with tokenizer_1.as_target_tokenizer():
34
- batch = tokenizer_1(
35
- input_text, truncation=True, padding="longest", return_tensors="pt"
36
- )
37
-
38
- raw_1 = model_1.generate(**batch)
39
-
40
- summary_1 = tokenizer_1.batch_decode(raw_1, skip_special_tokens=True)
41
-
42
- summed_1 = summary_1[0]
43
-
44
- lines1 = summed_1.split(". ")
45
-
46
- for i in range(len(lines1)):
47
- lines1[i] = "* " + lines1[i]
48
-
49
- summ_bullet1 = "\n".join(lines1)
50
-
51
- return summ_bullet1
52
-
53
-
54
- summary1 = gr.Interface(
55
- fn=summarizer1, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Textbox(label="")
56
- )
57
-
58
-
59
- modchoice_2 = (
60
- "chinhon/pegasus-newsroom-summarizer_02"
61
- )
62
-
63
- def summarizer2(text):
64
- input_text = clean_text(text)
65
-
66
- tokenizer_2 = AutoTokenizer.from_pretrained(modchoice_2)
67
-
68
- model_2 = AutoModelForSeq2SeqLM.from_pretrained(modchoice_2)
69
-
70
- with tokenizer_2.as_target_tokenizer():
71
- batch = tokenizer_2(
72
- input_text, truncation=True, padding="longest", return_tensors="pt"
73
- )
74
-
75
- raw_2 = model_2.generate(**batch)
76
-
77
- summary_2 = tokenizer_2.batch_decode(raw_2, skip_special_tokens=True)
78
-
79
- summed_2 = summary_2[0]
80
-
81
- lines2 = summed_2.split(". ")
82
-
83
- for i in range(len(lines2)):
84
- lines2[i] = "* " + lines2[i]
85
-
86
- summ_bullet2 = "\n".join(lines2)
87
-
88
- return summ_bullet2
89
-
90
- summary2 = gr.Interface(
91
- fn=summarizer2, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Textbox(label="")
92
- )
93
-
94
-
95
- Parallel(
96
- summary1,
97
- summary2,
98
- title="Compare 2 AI Summarizers",
99
- inputs=gr.inputs.Textbox(lines=20, label="Paste your news story here, and choose from 2 suggested summaries"),
100
- ).launch(enable_queue=True)