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( '''

A Legal document summerizer.

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()