Spaces:
Runtime error
Runtime error
Commit
·
d98294a
1
Parent(s):
575be67
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the summarization pipeline
|
| 5 |
+
summarizer = pipeline("summarization", model="t5-small", tokenizer="t5-small")
|
| 6 |
+
|
| 7 |
+
# Function for text summarization
|
| 8 |
+
def summarize_text(text):
|
| 9 |
+
if text:
|
| 10 |
+
summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
|
| 11 |
+
return summary[0]['summary_text']
|
| 12 |
+
return "Please enter text to summarize."
|
| 13 |
+
|
| 14 |
+
# Create a Gradio interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=summarize_text,
|
| 17 |
+
inputs=gr.inputs.Textbox(lines=10, label="Enter text to summarize"),
|
| 18 |
+
outputs=gr.outputs.Textbox(label="Summary"),
|
| 19 |
+
title="Text Summarization",
|
| 20 |
+
description="Use the model to summarize text."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Launch the Gradio interface
|
| 24 |
+
iface.launch()
|