Spaces:
Build error
Build error
initial version
Browse files- app.py +18 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("mmcquade11/autonlp-reuters-summarization-34018133")
|
6 |
+
model = AutoModelWithLMHead.from_pretrained("mmcquade11/autonlp-reuters-summarization-34018133")
|
7 |
+
|
8 |
+
def summarize(text):
|
9 |
+
input_ids = torch.tensor(tokenizer.encode(text, add_special_tokens=True)).unsqueeze(0)
|
10 |
+
summary_ids = model.generate(input_ids, num_beams=4, max_length=100, early_stopping=True)
|
11 |
+
return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
12 |
+
|
13 |
+
def summarize_text(text):
|
14 |
+
return summarize(text)
|
15 |
+
|
16 |
+
iface = gr.Interface(summarize_text, "textbox", "label")
|
17 |
+
if __name__ == "__main__":
|
18 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|