File size: 2,087 Bytes
4a017fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
import streamlit as st
from transformers import pipeline
import spacy
from io import StringIO

# Load Hugging Face's pre-trained NER model
nlp = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english")

# Sample regulations database (can be expanded with more detailed regulations)
regulations = {
    "pollution_limit": "Air pollution should not exceed 100 µg/m³ of particulate matter.",
    "waste_management": "Waste should be sorted into recyclable and non-recyclable categories.",
}

# Function to check compliance with regulations
def check_compliance(document_text):
    entities = nlp(document_text)
    compliance_feedback = []
    
    # Check for pollution limit violations
    if "pollution" in document_text.lower():
        compliance_feedback.append("Check pollution limits: Ensure PM2.5 does not exceed 100 µg/m³.")
    
    # Check for waste management practices
    if "waste" in document_text.lower():
        compliance_feedback.append("Check waste management: Ensure waste is properly sorted.")
    
    return compliance_feedback

# Streamlit App
st.title("🌱 Environmental Compliance Checker")

# Upload document
uploaded_file = st.file_uploader("Upload Environmental Report", type=["txt", "pdf", "docx"])

if uploaded_file is not None:
    # Read the file content
    file_content = uploaded_file.read().decode("utf-8")  # assuming it's a text file
    st.text_area("Uploaded Document", file_content, height=300)

    # Check compliance with regulations
    st.subheader("Compliance Feedback")
    feedback = check_compliance(file_content)
    
    if feedback:
        for item in feedback:
            st.write(f"- {item}")
    else:
        st.write("No compliance issues found.")
    
    # Optional: Provide NLP-based analysis or highlight regulations mentioned in the document
    st.subheader("Regulation Mentions in Document")
    entities = nlp(file_content)
    for entity in entities:
        st.write(f"Entity: {entity['word']} - Label: {entity['entity']}")

else:
    st.write("Please upload a document to check compliance.")