Spaces:
Sleeping
Sleeping
import torch | |
import gradio as gr | |
from transformers import pipeline | |
# Initialize the summarization pipeline (without float16 for CPU) | |
pipe = pipeline("summarization", model="Falconsai/text_summarization") | |
# Store the history | |
history = [] | |
# Define the summarize function | |
def summarize(input, clear_history=False): | |
# Clear history if the flag is set | |
if clear_history: | |
history.clear() | |
return "History cleared!" | |
# Get the summary | |
output = pipe(input) | |
summary = output[0]['summary_text'] | |
# Store the summary in history | |
history.append(summary) | |
# Return the summary along with the history | |
return summary, history | |
# Define the Gradio interface | |
iface = gr.Interface( | |
fn=summarize, | |
inputs=[ | |
gr.Textbox(lines=10, placeholder="Enter text to summarize here..."), | |
gr.Checkbox(label="Clear history", value=False) # Checkbox to clear history | |
], | |
outputs=["text", "json"], # Show summary and history in json format | |
title="Text Summarizer", | |
description="Enter a long piece of text, and the summarizer will provide a concise summary. You can also clear the history of summaries." | |
) | |
# Launch the interface | |
if __name__ == "__main__": | |
iface.launch() | |