gaialive commited on
Commit
fb3284b
·
verified ·
1 Parent(s): 71366d7

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +28 -0
  2. app.py +118 -0
Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.13.5-slim
2
+
3
+ # Create a dedicated directory for the application
4
+ WORKDIR /app
5
+
6
+ # Install system dependencies
7
+ RUN apt-get update && apt-get install -y \
8
+ build-essential \
9
+ curl \
10
+ git \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Copy application files
14
+ COPY requirements.txt ./
15
+ COPY app.py ./
16
+ COPY agents/ ./agents/
17
+
18
+ # Install Python dependencies
19
+ RUN pip3 install -r requirements.txt
20
+
21
+ # Expose the Streamlit port
22
+ EXPOSE 8501
23
+
24
+ # Healthcheck for the container
25
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
26
+
27
+ # Run the application
28
+ ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Main entry point for the ESG AI web application.
3
+
4
+ This script exposes a single Streamlit application that aggregates all of the
5
+ individual modules implemented in this repository. Each module focuses on a
6
+ distinct portion of the ESG workflow (e.g. template generation, planning,
7
+ report generation, compliance checking, score evaluation and greenwashing
8
+ analysis) and exposes its own top‑level UI function. The `app.py` file
9
+ provides a simple sidebar for users to switch between these modules and
10
+ delegates rendering to the appropriate function. Because the module
11
+ implementations live in separate files, this entry point remains light
12
+ weight and easy to maintain.
13
+
14
+ To add a new module to the application simply implement a function that
15
+ presents the user interface (for example `show_module1_ui`), place it in a
16
+ Python file at the top level of the repository (e.g. `module1_template.py`)
17
+ and add an entry for it to the `MODULE_REGISTRY` dictionary below.
18
+ """
19
+ import os
20
+ import sys
21
+
22
+ # Add the project root to the Python path to allow for module imports
23
+ sys.path.insert(0, os.path.abspath('.'))
24
+
25
+ import importlib
26
+ import streamlit as st
27
+
28
+ # ---------------------------------------------------------------------------
29
+ # Module registry
30
+ #
31
+ # The keys are the human friendly names that will appear in the sidebar
32
+ # selectbox. The values are tuples containing the import path and the name
33
+ # of the function to call. New modules should be registered here. If a
34
+ # module cannot be imported at runtime a friendly error will be displayed.
35
+ # ---------------------------------------------------------------------------
36
+ MODULE_REGISTRY = {
37
+ "1. Tạo mẫu kế hoạch bền vững": ("agents.module1_template", "show_module1_ui"),
38
+ "2. Tinh chỉnh kế hoạch bền vững": ("agents.module2_planner", "show_module2_ui"),
39
+ "3. Tạo báo cáo ESG tự động": ("agents.module3_report", "show_module3_ui"),
40
+ "4. Kiểm tra tuân thủ đa khung": ("agents.module4_compliance", "show_module4_ui"),
41
+ "5. Đánh giá và điểm số ESG": ("agents.module5_score", "show_module5_ui"),
42
+ "6. Kiểm tra greenwashing": ("agents.module6_greenwash", "show_module6_ui"),
43
+ }
44
+
45
+
46
+ def _load_module_ui(module_name: str, function_name: str):
47
+ """Attempt to import and retrieve the UI function from a module.
48
+
49
+ Parameters
50
+ ----------
51
+ module_name: str
52
+ The module to import. Should be a top level Python file without
53
+ `.py` extension, for example ``module3_report``.
54
+ function_name: str
55
+ The name of the function within the module that renders the UI.
56
+
57
+ Returns
58
+ -------
59
+ callable
60
+ A callable function if import succeeded. Otherwise a lambda that
61
+ displays a warning.
62
+ """
63
+ try:
64
+ module = importlib.import_module(module_name)
65
+ except ModuleNotFoundError as exc:
66
+ def _missing_ui(exc=exc):
67
+ st.warning(
68
+ f"Không thể tải module '{module_name}'. Vui lòng kiểm tra rằng "
69
+ f"file '{module_name}.py' tồn tại trong thư mục dự án và chứa "
70
+ f"một hàm có tên '{function_name}'.\n\nChi tiết lỗi: {exc}"
71
+ )
72
+ return _missing_ui
73
+ # module loaded, try to get the function
74
+ ui_func = getattr(module, function_name, None)
75
+ if ui_func is None:
76
+ def _missing_func():
77
+ st.warning(
78
+ f"Module '{module_name}' được tìm thấy nhưng không chứa hàm "
79
+ f"'{function_name}'. Vui lòng định nghĩa hàm giao diện đúng tên."
80
+ )
81
+ return _missing_func
82
+ return ui_func
83
+
84
+
85
+ def main() -> None:
86
+ """Main function executed by Streamlit to run the multi‑module application."""
87
+ st.set_page_config(
88
+ page_title="ESG AI Web Application",
89
+ layout="wide",
90
+ initial_sidebar_state="expanded",
91
+ )
92
+
93
+ st.sidebar.title("📘 Chức năng ESG")
94
+ module_key = st.sidebar.selectbox(
95
+ label="Chọn chức năng",
96
+ options=list(MODULE_REGISTRY.keys()),
97
+ index=0,
98
+ )
99
+
100
+ # Unpack module path and function name
101
+ module_name, function_name = MODULE_REGISTRY[module_key]
102
+
103
+ # Display header for the chosen module
104
+ st.title(module_key)
105
+
106
+ # Resolve and call UI function
107
+ ui_function = _load_module_ui(module_name, function_name)
108
+ try:
109
+ ui_function()
110
+ except Exception as err:
111
+ st.error(
112
+ "Đã xảy ra lỗi khi chạy module. Vui lòng kiểm tra lại mã nguồn."\
113
+ f"\n\nChi tiết lỗi: {err}"
114
+ )
115
+
116
+
117
+ if __name__ == "__main__":
118
+ main()