File size: 4,250 Bytes
898d64f
cbbfdce
ef5d679
21b05f2
2a0f339
 
5d68fbb
cbbfdce
 
 
edc682e
5797bd3
 
 
 
 
 
 
 
543501a
 
30e73d2
 
543501a
5797bd3
 
 
4b3dbbf
5797bd3
 
543501a
5797bd3
 
cbbfdce
79ea0e3
 
 
 
 
 
 
 
 
 
 
 
 
543501a
79ea0e3
543501a
 
79ea0e3
 
ef41aa4
79ea0e3
 
 
ef41aa4
79ea0e3
 
437d310
79ea0e3
 
 
2df5cf1
79ea0e3
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
import torch
import gradio as gr
from transformers import pipeline
from transformers import T5ForConditionalGeneration, T5Tokenizer
model_path='Sibinraj/T5-finetuned-dialogue_sumxx'
model = T5ForConditionalGeneration.from_pretrained(model_path)
tokenizer = T5Tokenizer.from_pretrained(model_path)



def summarize_text(text,max_length):
    # Preprocess the text
    inputs = tokenizer.encode(
        "summarize: " + text,
        return_tensors='pt',
        max_length=512,
        truncation=True,
        padding='max_length'
    )
    
    # Validate max_length
    # if not isinstance(max_length, int) or max_length <= 0:
    #     max_length = 50
    
    # Generate the summary
    summary_ids = model.generate(
        inputs,
        max_length=max_length,
        num_beams=5,
    )
    
    # Decode and return the summary
    return tokenizer.decode(summary_ids[0], skip_special_tokens=True)

# interface = gr.Interface(
#     fn=summarize_text,
#     inputs=[
#         gr.Textbox(lines=10, placeholder='Enter Text Here...', label='Input text'),
#         gr.Slider(minimum=10, maximum=150, step=1, value=50, label='Max Length')
#     ],
#     outputs=gr.Textbox(label='Summarized Text'),
#     title='Text Summarizer using T5-finetuned-dialogue_sumxx',
#     examples=[
#         ['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.', 50],
#         ['#Person1#: Is this the workshop to prepare for an interview? #Person2#: This is the interview class. Welcome to our class. #Person1#: I am really excited to be taking this workshop so that I can get ready for my interview next week. #Person2#: We are all learning things that will help us in our interview. What do you think are some important considerations going into your interview? #Person1#: I think that we should dress neatly and appropriately. #Person2#: Yes. Second, as you can imagine, attitude and friendliness go a long way. #Person1#: Yes, and I always feel much better when I am friendly. #Person2#: Believe it or not, the interviewers are as interested in your questions as they are in your answers. #Person1#: Any more hints as to what I should do in an interview? #Person2#: Always be honest with your answers. The interviewers really do want to know if you will be a good fit for them.', 50]
#     ]
# )

# interface.launch()


with gr.Blocks() as demo:
    text_input = gr.Textbox(label="Input Text")
    max_length = gr.Slider(minimum=10, maximum=150, value=50, step=5, label="Max Length (words)")
    output_text = gr.Textbox(label="Summary")
    gr.Interface(
        fn=summarize_text,
        inputs=[text_input, max_length],
        outputs=output_text,
        examples=[['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.']],
                  
        title="Text Summarization",
        description="Summarize text using a fine-tuned T5 model.",
    )

demo.launch()