File size: 1,365 Bytes
d787032
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline,AutoTokenizer, AutoModelForSeq2SeqLM

def easyterms(text:str)->str:
        print("In summerizing function of easyterms")
        tokenizer = AutoTokenizer.from_pretrained("EasyTerms/etsummerizer_v2")
        model = AutoModelForSeq2SeqLM.from_pretrained("EasyTerms/etsummerizer_v2")

        inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
        summary_ids = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], max_length=128, num_beams=4)
        summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
        return summary

def summerize(Option:str, Text:str)-> str:
    print(Option)
    if Option == "text":
        return easyterms(Text)
    else:
        return "Input is a URL string"
intro = gr.Markdown(
        '''
        <center><h1>A Legal document summerizer.</h1></span>  
        
        If you want to better understand legal text or document, this platform is for you. By choosing the url option you submit a url whose content will in turn be summerized for you.
        Otherwhise you can choose the text option and submit your own text to be summerized.

        '''
    )

interface = gr.Interface(
    fn=summerize,
    inputs=[gr.Radio(["url", "text"]),"text"],
    outputs=["text"]
)

interface.launch()