Text_Summarizer / app.py
SyedMohammedSathiq's picture
app.py
4492537 verified
raw
history blame
1.71 kB
import torch
import gradio as gr
from transformers import pipeline
# Initialize the summarization pipeline
pipe = pipeline("summarization", model="Falconsai/text_summarization")
# Store chat history as a list of tuples [(user_input, summary), ...]
chat_history = []
# Define the summarize function
def summarize(input_text, clear_history=False):
global chat_history
# Clear history if requested
if clear_history:
chat_history = []
return chat_history
# Generate the summary
output = pipe(input_text)
summary = output[0]['summary_text']
# Append the user's input and the summary to chat history
chat_history.append(("User: " + input_text, "Summarizer: " + summary))
# Return the updated chat history
return chat_history
# Define the Gradio interface
with gr.Blocks() as interface:
# Title and description
gr.Markdown("# ChatGPT-like Text Summarizer")
gr.Markdown("Enter a long piece of text, and the summarizer will provide a concise summary. History will appear like a chat interface.")
# Input section
with gr.Row():
input_text = gr.Textbox(lines=10, placeholder="Enter text to summarize here...", label="Input Text")
clear_history_btn = gr.Button("Clear History")
# Chatbot-style output
chatbot = gr.Chatbot(label="History")
# Submit button for summarization
submit_button = gr.Button("Summarize")
# Functionality for buttons
submit_button.click(summarize, inputs=[input_text, gr.State(False)], outputs=chatbot)
clear_history_btn.click(summarize, inputs=["", gr.State(True)], outputs=chatbot)
# Launch the interface
if __name__ == "__main__":
interface.launch()