EngrNarmeen commited on
Commit
4a017fc
·
verified ·
1 Parent(s): fa82fa1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import spacy
4
+ from io import StringIO
5
+
6
+ # Load Hugging Face's pre-trained NER model
7
+ nlp = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english")
8
+
9
+ # Sample regulations database (can be expanded with more detailed regulations)
10
+ regulations = {
11
+ "pollution_limit": "Air pollution should not exceed 100 µg/m³ of particulate matter.",
12
+ "waste_management": "Waste should be sorted into recyclable and non-recyclable categories.",
13
+ }
14
+
15
+ # Function to check compliance with regulations
16
+ def check_compliance(document_text):
17
+ entities = nlp(document_text)
18
+ compliance_feedback = []
19
+
20
+ # Check for pollution limit violations
21
+ if "pollution" in document_text.lower():
22
+ compliance_feedback.append("Check pollution limits: Ensure PM2.5 does not exceed 100 µg/m³.")
23
+
24
+ # Check for waste management practices
25
+ if "waste" in document_text.lower():
26
+ compliance_feedback.append("Check waste management: Ensure waste is properly sorted.")
27
+
28
+ return compliance_feedback
29
+
30
+ # Streamlit App
31
+ st.title("🌱 Environmental Compliance Checker")
32
+
33
+ # Upload document
34
+ uploaded_file = st.file_uploader("Upload Environmental Report", type=["txt", "pdf", "docx"])
35
+
36
+ if uploaded_file is not None:
37
+ # Read the file content
38
+ file_content = uploaded_file.read().decode("utf-8") # assuming it's a text file
39
+ st.text_area("Uploaded Document", file_content, height=300)
40
+
41
+ # Check compliance with regulations
42
+ st.subheader("Compliance Feedback")
43
+ feedback = check_compliance(file_content)
44
+
45
+ if feedback:
46
+ for item in feedback:
47
+ st.write(f"- {item}")
48
+ else:
49
+ st.write("No compliance issues found.")
50
+
51
+ # Optional: Provide NLP-based analysis or highlight regulations mentioned in the document
52
+ st.subheader("Regulation Mentions in Document")
53
+ entities = nlp(file_content)
54
+ for entity in entities:
55
+ st.write(f"Entity: {entity['word']} - Label: {entity['entity']}")
56
+
57
+ else:
58
+ st.write("Please upload a document to check compliance.")
59
+