sohomghosh commited on
Commit
54542e2
1 Parent(s): 3b5dbc3

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
+ import gradio as gr
5
+ from torch import nn
6
+
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained("nlpaueb/sec-bert-base")
9
+
10
+ model_fine_tuned_pt = AutoModelForSequenceClassification.from_pretrained("model/")
11
+
12
+ di = {0: 'Access to Communications', 1: 'Access to Finance', 2: 'Access to Health Care', 3: 'Accounting', 4: 'Biodiversity & Land Use', 5: 'Board', 6: 'Business Ethics', 7: 'Carbon Emissions', 8: 'Chemical Safety', 9: 'Climate Change Vulnerability', 10: 'Community Relations', 11: 'Consumer Financial Protection', 12: 'Controversial Sourcing', 13: 'Electronic Waste', 14: 'Financing Environmental Impact', 15: 'Health & Demographic Risk', 16: 'Human Capital Development', 17: 'Labor Management', 18: 'Opportunities in Clean Tech', 19: 'Opportunities in Green Building', 20: 'Opportunities in Nutrition & Health', 21: 'Opportunities in Renewable Energy', 22: 'Ownership & Control', 23: 'Packaging Material & Waste', 24: 'Pay', 25: 'Privacy & Data Security', 26: 'Product Carbon Footprint', 27: 'Product Safety & Quality', 28: 'Raw Material Sourcing', 29: 'Responsible Investment', 30: 'Supply Chain Labor Standards', 31: 'Toxic Emissions & Waste', 32: 'Water Stress'}
13
+
14
+ def fns(input_text):
15
+ predict_input_pt = tokenizer(input_text, truncation = True, padding = True, return_tensors = 'pt' )
16
+
17
+ ouput_pt = model_fine_tuned_pt(**predict_input_pt)
18
+
19
+ prediction_value_pt = torch.argmax(ouput_pt[0], dim = 1 ).item()
20
+
21
+ probab = nn.functional.softmax(ouput_pt[0], dim=-1).max().item()
22
+
23
+ if probab>=.7:
24
+ ans = di[prediction_value_pt]
25
+ else:
26
+ ans = "Sorry! We are not confident of the ESG issue in this case."
27
+
28
+ return ans
29
+
30
+ demo = gr.Interface(title="ESG Issue Detector (EID)", fn=fns, inputs="text", outputs="text", examples=["Partners Capital Appoints Kristen Eshak Weldon Global Head of ESG and Impact Investing","United Natural Foods Unveils Sustainability Goals Covering Climate, Waste Reduction and Food Access"])
31
+
32
+ demo.launch()