Shredder commited on
Commit
0171406
1 Parent(s): dd9537d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -9
app.py CHANGED
@@ -5,21 +5,66 @@ from sus_fls import get_sustainability,fls
5
  from Cuad_others import quad,summarize_text,fin_ner
6
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
 
8
-
9
- #CUAD STARTS
10
  def load_questions():
11
  questions = []
12
- with open('questions.txt') as f:
13
  questions = f.readlines()
14
  return questions
15
  questions = load_questions()
16
 
 
17
  def mainFun(query,file):
18
- answer,answer_p=quad(query,file.name)
19
- return answer_p,summarize_text(answer),fin_ner(answer),score_fincat(answer),get_sustainability(answer),fls(answer)
20
-
21
-
22
- iface = gr.Interface(fn=mainFun, inputs=[gr.Dropdown(choices=questions,label='SEARCH QUERY'),gr.inputs.File(label='TXT FILE')], title="CONBERT",description="CONTRACT REVIEW TOOL",article='Article', outputs=[gr.outputs.Textbox(label='Answer'),gr.outputs.Textbox(label='Summary'),gr.HighlightedText(label='NER'),gr.HighlightedText(label='CLAIM'),gr.HighlightedText(label='SUSTAINABILITY'),gr.HighlightedText(label='FLS')], allow_flagging="never")
23
 
 
 
24
 
25
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from Cuad_others import quad,summarize_text,fin_ner
6
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
7
 
 
 
8
  def load_questions():
9
  questions = []
10
+ with open('questionshort.txt') as f:
11
  questions = f.readlines()
12
  return questions
13
  questions = load_questions()
14
 
15
+ answer_main=''
16
  def mainFun(query,file):
17
+ text=''
18
+ with open(file.name) as f:
19
+ text = f.read()
20
+ answer_main,answer_p=quad(query,file)
21
+ return text,answer_p,summarize_text(answer_main)
22
 
23
+ def mainFun2(temp):
24
+ return fin_ner(temp.split('Probability:')[0])
25
 
26
+ def mainFun3(temp):
27
+ return score_fincat(temp.split('Probability:')[0])
28
+
29
+ def mainFun4(temp):
30
+ return get_sustainability(temp.split('Probability:')[0])
31
+
32
+ def mainFun5(temp):
33
+ return fls(temp.split('Probability:')[0])
34
+
35
+
36
+ demo = gr.Blocks()
37
+ with demo:
38
+
39
+ #FETCH AND DISPLAY CONTRACT
40
+ txt_file = gr.File(label='CONTRACT')
41
+ text = gr.Textbox(lines=10)
42
+ selected_ques=gr.Dropdown(choices=questions,label='SEARCH QUERY')
43
+ b1 = gr.Button("Analyze File")
44
+
45
+ #DISPLAY ANSWER AND SUMMARIZATION
46
+ answer = gr.Textbox(lines=2)
47
+ summarize = gr.Textbox(lines=2)
48
+ b1.click(mainFun, inputs=[selected_ques,txt_file], outputs=[text,answer,summarize])
49
+
50
+ #DISPLAY NER
51
+ b2=gr.Button("Get NER")
52
+ label_ner = gr.HighlightedText()
53
+ b2.click(mainFun2,inputs=answer,outputs=label_ner)
54
+
55
+ #DISPLAY CLAIMS
56
+ b3=gr.Button("Get CLAIM")
57
+ label_claim = gr.HighlightedText()
58
+ b3.click(mainFun3,inputs=answer,outputs=label_claim)
59
+
60
+ #DISPLAY SUSTAINABILITY
61
+ b4=gr.Button("Get SUSTAINABILITY")
62
+ label_sus = gr.HighlightedText()
63
+ b4.click(mainFun4,inputs=answer,outputs=label_sus)
64
+
65
+ #DISPLAY FLS
66
+ b5=gr.Button("Get FLS")
67
+ label_fls = gr.HighlightedText()
68
+ b5.click(mainFun5,inputs=answer,outputs=label_fls)
69
+
70
+ demo.launch()