From 4c4dfee82cb9b7db7355714a00601ba23bd4d03d Mon Sep 17 00:00:00 2001 From: Bipul Kumar Sharma Date: Sat, 22 Mar 2025 00:54:24 +0530 Subject: [PATCH] 1st Commit --- .../project.py | 151 ++++++++++++++++++ .../readme.md | 100 ++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/project.py create mode 100644 community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/readme.md diff --git a/community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/project.py b/community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/project.py new file mode 100644 index 0000000..9d969c4 --- /dev/null +++ b/community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/project.py @@ -0,0 +1,151 @@ +import streamlit as st +from dotenv import load_dotenv +from pathlib import Path +import os + +# Import Camel-AI and OWL modules +from camel.models import ModelFactory +from camel.types import ModelPlatformType, ModelType +from camel.logger import set_log_level +from camel.societies import RolePlaying +from camel.toolkits import ( + ExcelToolkit, + SearchToolkit, + CodeExecutionToolkit, +) +from owl.utils import run_society +from owl.utils import DocumentProcessingToolkit + +# Set log level to see detailed logs (optional) +set_log_level("DEBUG") + +# Load environment variables from .env file if available + +load_dotenv() + +def construct_society(question: str) -> RolePlaying: + r"""Construct a society of agents based on the given question. + + Args: + question (str): The task or question to be addressed by the society. + + Returns: + RolePlaying: A configured society of agents ready to address the question. + """ + + # Create models for different components + models = { + "user": ModelFactory.create( + model_platform=ModelPlatformType.OPENAI, + model_type=ModelType.GPT_4O, + model_config_dict={"temperature": 0}, + ), + "assistant": ModelFactory.create( + model_platform=ModelPlatformType.OPENAI, + model_type=ModelType.GPT_4O, + model_config_dict={"temperature": 0}, + ), + } + + # Configure toolkits + tools = [ + *CodeExecutionToolkit(sandbox="subprocess", verbose=True).get_tools(), + SearchToolkit().search_duckduckgo, + SearchToolkit().search_wiki, + SearchToolkit().search_baidu, + *ExcelToolkit().get_tools(), + ] + + # Configure agent roles and parameters + user_agent_kwargs = {"model": models["user"]} + assistant_agent_kwargs = {"model": models["assistant"], "tools": tools} + + # Configure task parameters + task_kwargs = { + "task_prompt": question, + "with_task_specify": False, + } + + # Create and return the society + society = RolePlaying( + **task_kwargs, + user_role_name="user", + user_agent_kwargs=user_agent_kwargs, + assistant_role_name="assistant", + assistant_agent_kwargs=assistant_agent_kwargs, + ) + + return society + +def summarize_section(): + st.header("Summarize Medical Text") + text = st.text_area("Enter medical text to summarize:", height=200) + if st.button("Summarize"): + if text: + # Create a task prompt for summarization + task_prompt = f"Summarize the following medical text:\n\n{text}" + society = construct_society(task_prompt) + with st.spinner("Running summarization society..."): + answer, chat_history, token_count = run_society(society) + st.subheader("Summary:") + st.write(answer) + st.write(chat_history) + else: + st.warning("Please enter some text to summarize.") + +def write_and_refine_article_section(): + st.header("Write and Refine Research Article") + topic = st.text_input("Enter the topic for the research article:") + outline = st.text_area("Enter an outline (optional):", height=150) + if st.button("Write and Refine Article"): + if topic: + # Create a task prompt for article writing and refinement + task_prompt = f"Write a research article on the topic: {topic}." + if outline.strip(): + task_prompt += f" Use the following outline as guidance:\n{outline}" + society = construct_society(task_prompt) + with st.spinner("Running research article society..."): + print(task_prompt) + answer, chat_history, token_count = run_society(society) + st.subheader("Article:") + st.write(answer) + st.write(chat_history) + else: + st.warning("Please enter a topic for the research article.") + +def sanitize_data_section(): + st.header("Sanitize Medical Data (PHI)") + data = st.text_area("Enter medical data to sanitize:", height=200) + if st.button("Sanitize Data"): + if data: + # Create a task prompt for data sanitization + task_prompt = f"Sanitize the following medical data by removing any protected health information (PHI):\n\n{data}" + society = construct_society(task_prompt) + with st.spinner("Running data sanitization society..."): + answer, chat_history, token_count = run_society(society) + st.subheader("Sanitized Data:") + st.write(answer) + st.write(chat_history) + else: + st.warning("Please enter medical data to sanitize.") + +def main(): + st.set_page_config(page_title="Multi-Agent AI System with Camel & OWL", layout="wide") + st.title("Multi-Agent AI System with Camel-AI and OWL") + + st.sidebar.title("Select Task") + task = st.sidebar.selectbox("Choose a task:", [ + "Summarize Medical Text", + "Write and Refine Research Article", + "Sanitize Medical Data (PHI)" + ]) + + if task == "Summarize Medical Text": + summarize_section() + elif task == "Write and Refine Research Article": + write_and_refine_article_section() + elif task == "Sanitize Medical Data (PHI)": + sanitize_data_section() + +if __name__ == "__main__": + main() diff --git a/community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/readme.md b/community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/readme.md new file mode 100644 index 0000000..c8e6204 --- /dev/null +++ b/community_usecase/PHI_Sanitization_Summarization_and_Article_Writing/readme.md @@ -0,0 +1,100 @@ +# 🚀 Collaborative Multi-Agent AI System + +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. + +--- + +## ✨ Features + +- **🤖 Multi-Agent Teamwork**: CAMEL-AI + OWL frameworks enable real-time collaboration between autonomous agents. +- **💡 Autonomous Agents**: Agents communicate, collaborate, and validate outputs for accurate results. +- **🔗 Seamless Integration**: CAMEL-AI for agent design + OWL for real-time task management. +- **🌐 Streamlit UI**: A clean, interactive app for easy task execution. +- **🚀 Use Cases**: + - Summarize medical texts in seconds. + - Automate research article generation. + - Sanitize PHI data for compliance. + +--- + +## 🛠️ How It Works + +1. **Agent Roles**: Defined using CAMEL-AI's `RolePlaying` class. +2. **Dynamic Toolkits**: Integrated CAMEL-AI's tools for agent functionality. +3. **Real-Time Management**: OWL framework ensures smooth task execution. +4. **User-Friendly Interface**: Streamlit provides an intuitive UI for users. + +--- + +## 🚀 Getting Started + +1. **Clone the repository**: + ```bash + git clone https://github.com/Bipul70701/Multi-Agent-System-OWL.git + cd Multi-Agent-System-OWL + ``` + +2. **Create a virtual environment**: + ```bash + python -m venv venv + ``` + +3. **Activate the virtual environment**: + - On Windows: + ```bash + venv\Scripts\activate + ``` + - On macOS/Linux: + ```bash + source venv/bin/activate + ``` + +4. **Install dependencies**: + ```bash + pip install -r requirements.txt + ``` + +5. **Run the Streamlit app**: + ```bash + streamlit run app.py + ``` + +--- + +## 🔧 Key Components + +- **CAMEL-AI**: Framework for designing and managing autonomous agents. +- **OWL**: Real-time task management and collaboration. +- **Streamlit**: Interactive web app for user interaction. + +--- + +## 📂 Project Structure + +``` +Multi-Agent-System-OWL/ +├── multiagentsystem.py # Streamlit application +├── owl/ # OWL framework and utilities +│ └── utils/ # Utility functions and helpers +├── requirements.txt # List of dependencies +└── README.md # Project documentation +``` + +--- + +## 🌟 Try It Yourself + +Check out the project on GitHub: +🔗 [GitHub Repository](https://github.com/Bipul70701/Multi-Agent-System-OWL) + +--- + +## 🙌 Credits + +- **CAMEL-AI**: For the multi-agent framework. +- **OWL**: For real-time task management. +- **Streamlit**: For the interactive UI. + +--- + +Made with ❤️ by Bipul Kumar Sharma \ No newline at end of file