Bipul8765 commited on
Commit
06c0b15
Β·
1 Parent(s): 446b799

1st Commit

Browse files
community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/project.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from dotenv import load_dotenv
3
+ from pathlib import Path
4
+ import os
5
+
6
+ # Import Camel-AI and OWL modules
7
+ from camel.models import ModelFactory
8
+ from camel.types import ModelPlatformType, ModelType
9
+ from camel.logger import set_log_level
10
+ from camel.societies import RolePlaying
11
+ from camel.toolkits import (
12
+ ExcelToolkit,
13
+ SearchToolkit,
14
+ CodeExecutionToolkit,
15
+ )
16
+ from owl.utils import run_society
17
+ from owl.utils import DocumentProcessingToolkit
18
+
19
+ # Set log level to see detailed logs (optional)
20
+ set_log_level("DEBUG")
21
+
22
+ # Load environment variables from .env file if available
23
+
24
+ load_dotenv()
25
+
26
+ def construct_society(question: str) -> RolePlaying:
27
+ r"""Construct a society of agents based on the given question.
28
+
29
+ Args:
30
+ question (str): The task or question to be addressed by the society.
31
+
32
+ Returns:
33
+ RolePlaying: A configured society of agents ready to address the question.
34
+ """
35
+
36
+ # Create models for different components
37
+ models = {
38
+ "user": ModelFactory.create(
39
+ model_platform=ModelPlatformType.OPENAI,
40
+ model_type=ModelType.GPT_4O,
41
+ model_config_dict={"temperature": 0},
42
+ ),
43
+ "assistant": ModelFactory.create(
44
+ model_platform=ModelPlatformType.OPENAI,
45
+ model_type=ModelType.GPT_4O,
46
+ model_config_dict={"temperature": 0},
47
+ ),
48
+ }
49
+
50
+ # Configure toolkits
51
+ tools = [
52
+ *CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(),
53
+ SearchToolkit().search_duckduckgo,
54
+ SearchToolkit().search_wiki,
55
+ SearchToolkit().search_baidu,
56
+ *ExcelToolkit().get_tools(),
57
+ ]
58
+
59
+ # Configure agent roles and parameters
60
+ user_agent_kwargs = {"model": models["user"]}
61
+ assistant_agent_kwargs = {"model": models["assistant"], "tools": tools}
62
+
63
+ # Configure task parameters
64
+ task_kwargs = {
65
+ "task_prompt": question,
66
+ "with_task_specify": False,
67
+ }
68
+
69
+ # Create and return the society
70
+ society = RolePlaying(
71
+ **task_kwargs,
72
+ user_role_name="user",
73
+ user_agent_kwargs=user_agent_kwargs,
74
+ assistant_role_name="assistant",
75
+ assistant_agent_kwargs=assistant_agent_kwargs,
76
+ )
77
+
78
+ return society
79
+
80
+ def summarize_section():
81
+ st.header("Summarize Medical Text")
82
+ text = st.text_area("Enter medical text to summarize:", height=200)
83
+ if st.button("Summarize"):
84
+ if text:
85
+ # Create a task prompt for summarization
86
+ task_prompt = f"Summarize the following medical text:\n\n{text}"
87
+ society = construct_society(task_prompt)
88
+ with st.spinner("Running summarization society..."):
89
+ answer, chat_history, token_count = run_society(society)
90
+ st.subheader("Summary:")
91
+ st.write(answer)
92
+ st.write(chat_history)
93
+ else:
94
+ st.warning("Please enter some text to summarize.")
95
+
96
+ def write_and_refine_article_section():
97
+ st.header("Write and Refine Research Article")
98
+ topic = st.text_input("Enter the topic for the research article:")
99
+ outline = st.text_area("Enter an outline (optional):", height=150)
100
+ if st.button("Write and Refine Article"):
101
+ if topic:
102
+ # Create a task prompt for article writing and refinement
103
+ task_prompt = f"Write a research article on the topic: {topic}."
104
+ if outline.strip():
105
+ task_prompt += f" Use the following outline as guidance:\n{outline}"
106
+ society = construct_society(task_prompt)
107
+ with st.spinner("Running research article society..."):
108
+ print(task_prompt)
109
+ answer, chat_history, token_count = run_society(society)
110
+ st.subheader("Article:")
111
+ st.write(answer)
112
+ st.write(chat_history)
113
+ else:
114
+ st.warning("Please enter a topic for the research article.")
115
+
116
+ def sanitize_data_section():
117
+ st.header("Sanitize Medical Data (PHI)")
118
+ data = st.text_area("Enter medical data to sanitize:", height=200)
119
+ if st.button("Sanitize Data"):
120
+ if data:
121
+ # Create a task prompt for data sanitization
122
+ task_prompt = f"Sanitize the following medical data by removing any protected health information (PHI):\n\n{data}"
123
+ society = construct_society(task_prompt)
124
+ with st.spinner("Running data sanitization society..."):
125
+ answer, chat_history, token_count = run_society(society)
126
+ st.subheader("Sanitized Data:")
127
+ st.write(answer)
128
+ st.write(chat_history)
129
+ else:
130
+ st.warning("Please enter medical data to sanitize.")
131
+
132
+ def main():
133
+ st.set_page_config(page_title="Multi-Agent AI System with Camel & OWL", layout="wide")
134
+ st.title("Multi-Agent AI System with Camel-AI and OWL")
135
+
136
+ st.sidebar.title("Select Task")
137
+ task = st.sidebar.selectbox("Choose a task:", [
138
+ "Summarize Medical Text",
139
+ "Write and Refine Research Article",
140
+ "Sanitize Medical Data (PHI)"
141
+ ])
142
+
143
+ if task == "Summarize Medical Text":
144
+ summarize_section()
145
+ elif task == "Write and Refine Research Article":
146
+ write_and_refine_article_section()
147
+ elif task == "Sanitize Medical Data (PHI)":
148
+ sanitize_data_section()
149
+
150
+ if __name__ == "__main__":
151
+ main()
community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/readme.md ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸš€ Collaborative Multi-Agent AI System
2
+
3
+ Welcome to my latest project: a **multi-agent AI platform** that automates complex tasks through teamwork! This system combines the power of **CAMEL-AI**, **OWL**, and **Streamlit** to create a seamless, interactive experience for task automation and collaboration.
4
+
5
+ ---
6
+
7
+ ## ✨ Features
8
+
9
+ - **πŸ€– Multi-Agent Teamwork**: CAMEL-AI + OWL frameworks enable real-time collaboration between autonomous agents.
10
+ - **πŸ’‘ Autonomous Agents**: Agents communicate, collaborate, and validate outputs for accurate results.
11
+ - **πŸ”— Seamless Integration**: CAMEL-AI for agent design + OWL for real-time task management.
12
+ - **🌐 Streamlit UI**: A clean, interactive app for easy task execution.
13
+ - **πŸš€ Use Cases**:
14
+ - Summarize medical texts in seconds.
15
+ - Automate research article generation.
16
+ - Sanitize PHI data for compliance.
17
+
18
+ ---
19
+
20
+ ## πŸ› οΈ How It Works
21
+
22
+ 1. **Agent Roles**: Defined using CAMEL-AI's `RolePlaying` class.
23
+ 2. **Dynamic Toolkits**: Integrated CAMEL-AI's tools for agent functionality.
24
+ 3. **Real-Time Management**: OWL framework ensures smooth task execution.
25
+ 4. **User-Friendly Interface**: Streamlit provides an intuitive UI for users.
26
+
27
+ ---
28
+
29
+ ## πŸš€ Getting Started
30
+
31
+ 1. **Clone the repository**:
32
+ ```bash
33
+ git clone https://github.com/Bipul70701/Multi-Agent-System-OWL.git
34
+ cd Multi-Agent-System-OWL
35
+ ```
36
+
37
+ 2. **Create a virtual environment**:
38
+ ```bash
39
+ python -m venv venv
40
+ ```
41
+
42
+ 3. **Activate the virtual environment**:
43
+ - On Windows:
44
+ ```bash
45
+ venv\Scripts\activate
46
+ ```
47
+ - On macOS/Linux:
48
+ ```bash
49
+ source venv/bin/activate
50
+ ```
51
+
52
+ 4. **Install dependencies**:
53
+ ```bash
54
+ pip install -r requirements.txt
55
+ ```
56
+
57
+ 5. **Run the Streamlit app**:
58
+ ```bash
59
+ streamlit run app.py
60
+ ```
61
+
62
+ ---
63
+
64
+ ## πŸ”§ Key Components
65
+
66
+ - **CAMEL-AI**: Framework for designing and managing autonomous agents.
67
+ - **OWL**: Real-time task management and collaboration.
68
+ - **Streamlit**: Interactive web app for user interaction.
69
+
70
+ ---
71
+
72
+ ## πŸ“‚ Project Structure
73
+
74
+ ```
75
+ Multi-Agent-System-OWL/
76
+ β”œβ”€β”€ multiagentsystem.py # Streamlit application
77
+ β”œβ”€β”€ owl/ # OWL framework and utilities
78
+ β”‚ └── utils/ # Utility functions and helpers
79
+ β”œβ”€β”€ requirements.txt # List of dependencies
80
+ └── README.md # Project documentation
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 🌟 Try It Yourself
86
+
87
+ Check out the project on GitHub:
88
+ πŸ”— [GitHub Repository](https://github.com/Bipul70701/Multi-Agent-System-OWL)
89
+
90
+ ---
91
+
92
+ ## πŸ™Œ Credits
93
+
94
+ - **CAMEL-AI**: For the multi-agent framework.
95
+ - **OWL**: For real-time task management.
96
+ - **Streamlit**: For the interactive UI.
97
+
98
+ ---
99
+
100
+ Made with ❀️ by Bipul Kumar Sharma