Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
# 1.
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
)
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
# Truncation=True ensures we don't exceed the 1024 token limit
|
| 33 |
-
results = summarizer(text, max_length=100, min_length=30, truncation=True)
|
| 34 |
-
return results[0]['summary_text']
|
| 35 |
-
|
| 36 |
-
demo = gr.Interface(
|
| 37 |
-
fn=summarize_text,
|
| 38 |
-
inputs=gr.Textbox(lines=10, placeholder="Paste text here..."),
|
| 39 |
-
outputs="textbox",
|
| 40 |
-
title="AI Text Summarizer"
|
| 41 |
-
)
|
| 42 |
|
|
|
|
| 43 |
if __name__ == "__main__":
|
| 44 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# 1. Load the model
|
| 6 |
+
# NOTE: Ensure your model is PUBLIC on Hugging Face
|
| 7 |
+
try:
|
| 8 |
+
pipe = pipeline("summarization", model="VoltIC/Automated-Text-Summarizer")
|
| 9 |
+
status = "Model loaded successfully!"
|
| 10 |
+
except Exception as e:
|
| 11 |
+
pipe = None
|
| 12 |
+
status = f"Error: {str(e)}"
|
| 13 |
|
| 14 |
+
def summarize(text):
|
| 15 |
+
if pipe is None:
|
| 16 |
+
return "Model not available. Check if repo is Public."
|
| 17 |
+
if not text.strip():
|
| 18 |
+
return "Please enter text."
|
| 19 |
+
|
| 20 |
+
result = pipe(text, max_length=130, min_length=30, do_sample=False)
|
| 21 |
+
return result[0]['summary_text']
|
| 22 |
|
| 23 |
+
# 2. Build UI using Blocks (Avoids the Interface IndexError)
|
| 24 |
+
with gr.Blocks() as app:
|
| 25 |
+
gr.Markdown("# Aditya's Automated Text Summarizer")
|
| 26 |
+
gr.Markdown(f"**Status:** {status}")
|
| 27 |
+
|
| 28 |
+
with gr.Row():
|
| 29 |
+
input_text = gr.Textbox(lines=10, label="Input Article", placeholder="Paste text here...")
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
submit_btn = gr.Button("Summarize")
|
| 33 |
+
|
| 34 |
+
with gr.Row():
|
| 35 |
+
output_text = gr.Textbox(label="Summary")
|
| 36 |
+
|
| 37 |
+
submit_btn.click(fn=summarize, inputs=input_text, outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
# 3. Launch
|
| 40 |
if __name__ == "__main__":
|
| 41 |
+
app.launch()
|