File size: 1,705 Bytes
d6c533e
 
 
 
4492537
7635e33
 
4492537
 
d6c533e
 
4492537
 
 
 
7635e33
4492537
 
7635e33
4492537
 
7635e33
4492537
 
 
 
 
 
d6c533e
 
4492537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6c533e
 
 
4492537
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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()