Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import pipeline
|
4 |
+
model_path=(".venv/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff")
|
5 |
+
|
6 |
+
pipe=pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16, device="cpu")
|
7 |
+
#pipe=pipeline("summarization", model="facebook/bart-large-cnn", torch_dtype=torch.bfloat16, device="cpu")
|
8 |
+
|
9 |
+
#pipe = pipeline("summarization", model="sshleifer/distilbart-cnn-6-6")
|
10 |
+
text_summary=pipeline(task="summarization", model=model_path, torch_dtype=torch.bfloat16)
|
11 |
+
|
12 |
+
|
13 |
+
def summary(input):
|
14 |
+
#max_input_len=1024
|
15 |
+
#if len(full_text.split()) > max_input_len:
|
16 |
+
# full_text = " ".join(full_text.split()[:max_input_len])
|
17 |
+
output=text_summary(input)
|
18 |
+
return output[0]['summary_text']
|
19 |
+
|
20 |
+
gr.close_all()
|
21 |
+
|
22 |
+
demo=gr.Interface(fn=summary,
|
23 |
+
inputs=[gr.Textbox(label='Input Text to Summarize', lines=1)],
|
24 |
+
outputs=[gr.Textbox(label='Summarized Text', lines=4)],
|
25 |
+
title='KS Text Summarizer',
|
26 |
+
description='This application will be used to summarize a corpus')
|
27 |
+
|
28 |
+
demo.launch()
|