Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +38 -0
- reqirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
MODEL_NAME = "facebook/bart-large-cnn"
|
| 6 |
+
|
| 7 |
+
# load model
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 10 |
+
|
| 11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
model = model.to(device)
|
| 13 |
+
|
| 14 |
+
def summarize(text):
|
| 15 |
+
if not text:
|
| 16 |
+
return "Please enter text"
|
| 17 |
+
|
| 18 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024).to(device)
|
| 19 |
+
|
| 20 |
+
summary_ids = model.generate(
|
| 21 |
+
inputs["input_ids"],
|
| 22 |
+
max_length=150,
|
| 23 |
+
min_length=50,
|
| 24 |
+
num_beams=4
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
| 28 |
+
return summary
|
| 29 |
+
|
| 30 |
+
app = gr.Interface(
|
| 31 |
+
fn=summarize,
|
| 32 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter long text here..."),
|
| 33 |
+
outputs="text",
|
| 34 |
+
title="LITVISION Summarizer",
|
| 35 |
+
description="AI-powered book and text summarization"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
app.launch()
|
reqirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
sentencepiece
|