File size: 1,288 Bytes
2e9a8c4
037452a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b2fb3c
b4a2027
 
 
 
037452a
 
 
 
 
 
 
 
 
 
 
9226486
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
import gradio as gr
import numpy as np
import pytesseract as pt
import pdf2image
from fpdf import FPDF
import re
import nltk
from nltk.tokenize import sent_tokenize
from nltk.tokenize import word_tokenize
import os
import pdfkit
import yake
from transformers import AutoTokenizer, AutoModelForPreTraining, AutoModel, AutoConfig
from summarizer import Summarizer,TransformerSummarizer
from transformers import pipelines
nltk.download('punkt')

 
model_name = 'nlpaueb/legal-bert-base-uncased'


# The setup of huggingface.co
custom_config = AutoConfig.from_pretrained(model_name)
custom_config.output_hidden_states=True
custom_tokenizer = AutoTokenizer.from_pretrained(model_name)
custom_model = AutoModel.from_pretrained(model_name, config=custom_config)
bert_legal_model = Summarizer(custom_model=custom_model, custom_tokenizer=custom_tokenizer)


def get_response(input_text):
  output_text= bert_legal_model(input_text,  min_length = 8, ratio = 0.05)
  output_text = output_text.replace('   ',' ')
  output_text = output_text .replace(',.',',')
  output_text = output_text .replace('\n','  ')
  output_text = output_text .replace('..','.')
  return output_text
  
  
 
iface = gr.Interface(
    get_response, 
    "text", 
    "text"
   )

if __name__ == "__main__":
    iface.launch()