Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Load the summarization model
|
| 6 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 7 |
+
|
| 8 |
+
# Define the function to summarize text
|
| 9 |
+
def summarize_text(text):
|
| 10 |
+
if not text.strip():
|
| 11 |
+
return "Please enter some text to summarize."
|
| 12 |
+
|
| 13 |
+
summary = summarizer(text, max_length=150, min_length=30, do_sample=False)
|
| 14 |
+
return summary[0]["summary_text"]
|
| 15 |
+
|
| 16 |
+
# Create the Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=summarize_text,
|
| 19 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter text to summarize..."),
|
| 20 |
+
outputs="text",
|
| 21 |
+
title="Text Summarization Chatbot",
|
| 22 |
+
description="Enter a long text passage, and the chatbot will summarize it for you using the 'facebook/bart-large-cnn' model.",
|
| 23 |
+
theme="compact"
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Launch the app
|
| 27 |
+
iface.launch()
|