Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("PRAli22/flan-t5-base-imdb-text-classification")
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained("PRAli22/flan-t5-base-imdb-text-classification")
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
def summarize(text):
|
11 |
+
inputs = tokenizer.encode_plus(text, padding='max_length', max_length=512, return_tensors='pt')
|
12 |
+
summarized_ids = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'],
|
13 |
+
max_length=150, num_beams=4, early_stopping=True)
|
14 |
+
|
15 |
+
return " ".join([tokenizer.decode(token_ids, skip_special_tokens=True)
|
16 |
+
for token_ids in summarized_ids])
|
17 |
+
|
18 |
+
|
19 |
+
css_code='body{background-image:url("https://media.istockphoto.com/id/1256252051/vector/people-using-online-translation-app.jpg?s=612x612&w=0&k=20&c=aa6ykHXnSwqKu31fFR6r6Y1bYMS5FMAU9yHqwwylA94=");}'
|
20 |
+
|
21 |
+
demo = gr.Interface(
|
22 |
+
fn=summarize,
|
23 |
+
inputs=
|
24 |
+
gr.Textbox(label="text", placeholder="Enter the text "),
|
25 |
+
|
26 |
+
outputs=gr.Textbox(label="summary"),
|
27 |
+
title="Text Summarizer",
|
28 |
+
description= "This is Text Summarizer System, it takes a text in English as inputs and returns it's summary",
|
29 |
+
css = css_code
|
30 |
+
)
|
31 |
+
|
32 |
+
demo.launch()
|