Spaces:
Runtime error
Runtime error
Commit
·
e759989
1
Parent(s):
834ba20
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("mynkchaudhry/Summarization-Pro")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("mynkchaudhry/Summarization-Pro")
|
7 |
+
|
8 |
+
def summarize(text):
|
9 |
+
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
|
10 |
+
summary_ids = model.generate(inputs, max_length=800, min_length=300, length_penalty=2.0, num_beams=4, early_stopping=True)
|
11 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
12 |
+
return summary
|
13 |
+
|
14 |
+
# Create a Gradio interface
|
15 |
+
interface = gr.Interface(theme="NoCrypt/miku",
|
16 |
+
fn=summarize,
|
17 |
+
inputs=gr.Textbox(lines=10, label="Input Text"),
|
18 |
+
outputs=gr.Textbox(label="Summary"),
|
19 |
+
title="Text Summarization Tool",
|
20 |
+
description="Enter a long text and get a summarized version of it.")
|
21 |
+
|
22 |
+
# Launch the interface
|
23 |
+
interface.launch()
|