File size: 2,591 Bytes
fb2d628
 
 
 
 
 
 
995aaf9
 
fb2d628
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
import requests 
import nltk
import json
import random
from utils import *

nltk.download('punkt')

# Function to handle summarization based on the selected method
def summarize(text: str, method: str) -> str:
    processed_text = ' '.join(text.split("\n"))
    chunks = split_chunk(text)
    tree = MemWalker(chunks)
    tree.build_memory_tree()
    summary = summarize_three_ways(chunks)
    
    #print(processed_text)

    if method == "Truncation":
        return summary['truncated']
    elif method == "Rewrite":
        return summary['rewrite']
    elif method == "Accumulate":
        return summary['accumulate']
    elif method == "Memory Tree":
        return tree.root.summary

example_transcript = get_example()

def clear_input():
    return "", "Truncation"

def load_example(index):
    return example_transcript[index]

def load_example_1():
    return load_example(0)
def load_example_2():
    return load_example(1)
def load_example_3():
    return load_example(2)
def load_example_4():
    return load_example(3)

# Create the interface
with gr.Blocks() as iface:
    text_input = gr.Textbox(lines=5, placeholder="Enter text to summarize here...", label="Input Transcript")
    method_input = gr.Radio(choices=["Truncation", "Rewrite", "Accumulate", "Memory Tree"], label="Summarization Method", value="Truncation")
    output_text = gr.Textbox(label="Summary")

    summarize_button = gr.Button("Summarize")
    clear_button = gr.Button("Clear Input")

    summarize_button.click(summarize, inputs=[text_input, method_input], outputs=output_text)
    clear_button.click(clear_input, outputs=[text_input, method_input])
    #gr.Exa
    #gr.Examples([example_transcript[:100]], inputs=[text_input], label=f"Example", fn=load_example)
    
    example_button_1 = gr.Button(f"Example {1}: {example_transcript[0][:600]}...")
    example_button_1.click(load_example_1, inputs = None, outputs=[text_input])
    
    example_button_2 = gr.Button(f"Example {2}: {example_transcript[1][:600]}...")
    example_button_2.click(load_example_2, inputs = None, outputs=[text_input])
    
    example_button_3 = gr.Button(f"Example {3}: {example_transcript[2][:600]}...")
    example_button_3.click(load_example_3, inputs = None, outputs=[text_input])
    
    example_button_4 = gr.Button(f"Example {4}: {example_transcript[3][:600]}...")
    example_button_4.click(load_example_4, inputs = None, outputs=[text_input])
    

# Launch the interface
iface.launch(share = True, debug = True)