Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
# Load the summarization model
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
|
| 7 |
+
def summarize_text(input_text, min_length, max_length):
|
| 8 |
+
# Summarize the input text
|
| 9 |
+
summary = summarizer(input_text, min_length=min_length, max_length=max_length, do_sample=False)
|
| 10 |
+
return summary[0]['summary_text']
|
| 11 |
+
|
| 12 |
+
# Create the Gradio interface
|
| 13 |
+
interface = gr.Interface(
|
| 14 |
+
fn=summarize_text,
|
| 15 |
+
inputs=[
|
| 16 |
+
gr.Textbox(label="Enter Text", placeholder="Type or paste your long text here...", lines=10),
|
| 17 |
+
gr.Slider(label="Minimum Length", minimum=10, maximum=50, step=1, value=10),
|
| 18 |
+
gr.Slider(label="Maximum Length", minimum=50, maximum=150, step=1, value=100),
|
| 19 |
+
],
|
| 20 |
+
outputs=gr.Textbox(label="Summary"),
|
| 21 |
+
title="Text Summarization App",
|
| 22 |
+
description="Enter a long piece of text, set the summary length, and click the button to get a summarized version."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the app
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
interface.launch()
|