Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

usecase: Add pptx_toolkit usecase app (#2562)

Sarthak Bhardwaj9f7f252344f4
diff --git a/examples/usecases/mistral_OCR/README.md b/examples/usecases/mistral_OCR/README.md
index d8a899790..3f1d71abf 100644
--- a/examples/usecases/mistral_OCR/README.md
+++ b/examples/usecases/mistral_OCR/README.md
@@ -84,5 +84,5 @@ requirements.txt # Python dependencies
streamlit
pillow
mistralai
-camel-ai==0.2.61
+camel-ai[all]==0.2.61
```
diff --git a/examples/usecases/mistral_OCR/requirements.txt b/examples/usecases/mistral_OCR/requirements.txt
index 52815067d..41e9bc444 100644
--- a/examples/usecases/mistral_OCR/requirements.txt
+++ b/examples/usecases/mistral_OCR/requirements.txt
@@ -1,4 +1,4 @@
-camel-ai==0.2.61
+camel-ai[all]==0.2.61
streamlit
pillow
mistralai
diff --git a/examples/usecases/pptx_toolkit_usecase/README.md b/examples/usecases/pptx_toolkit_usecase/README.md
new file mode 100644
index 000000000..e4bedb65e
--- /dev/null
+++ b/examples/usecases/pptx_toolkit_usecase/README.md
@@ -0,0 +1,100 @@
+# 📑 AI-Powered PPTX Generator (CAMEL-AI)
+
+Generate beautiful, professional PowerPoint presentations (PPTX) on any topic in seconds!
+Built with [CAMEL-AI](https://github.com/camel-ai/camel), OpenAI, and Streamlit.
+
+---
+
+## 🚀 Features
+
+- 🔥 Generate engaging, multi-slide PPTX files for any topic—instantly!
+- 💡 Uses OpenAI to create bullet, step-by-step (pentagon/chevron), and table slides.
+- 🖼️ Optional support for auto-inserting images using [Pexels](https://www.pexels.com/api/).
+- 📦 All output is 100% local and ready for download.
+
+---
+
+## 🛠️ Installation
+
+```bash
+# 1. Create a fresh virtual environment (recommended)
+python3 -m venv .venv
+source .venv/bin/activate # On Windows: .venv\Scripts\activate
+
+# 2. Install the specific CAMEL-AI version (and requirements)
+pip install camel-ai[all]==0.2.62 streamlit openai
+
+# 3. (Optional) Get a [Pexels API key](https://www.pexels.com/api/) if you want slides with images
+```
+
+---
+
+## 📝 Usage
+
+1. **Get your OpenAI API key:**
+ [Create one here](https://platform.openai.com/account/api-keys).
+
+2. **(Optional) Get your Pexels API key:**
+ [Request it here](https://www.pexels.com/api/) if you want to auto-insert images.
+
+3. **Clone this repo or copy the app file:**
+ ```bash
+ git clone https://github.com/camel-ai/camel
+ cd examples/usecases/pptx_toolkit_usecase
+ # Or just copy the .py script to your working directory
+ ```
+
+4. **Run the Streamlit app:**
+ ```bash
+ streamlit run app_pptx.py
+ ```
+
+5. **Open the Streamlit UI in your browser** (default: http://localhost:8501).
+
+6. **Enter your API keys, type your topic, set slide count, and hit "Generate Presentation"!**
+
+---
+
+## 🏗️ How it Works
+
+- You provide a topic and desired slide count.
+- The app prompts OpenAI GPT-4o or GPT-4 (you can change the model in code) to generate slide content in a format CAMEL-AI's `PPTXToolkit` can use.
+- At least one step-by-step slide and one table slide are always included; at least two slides will contain images if you provide a Pexels API key.
+- The toolkit generates a `.pptx` file named after your topic, ready for download.
+
+---
+
+## ⚙️ Example Prompt Structure
+
+<details>
+<summary>See Example</summary>
+
+```json
+[
+ {"title": "AI Agents", "subtitle": "Exploring the world of artificial intelligence agents"},
+ {"heading": "Types of AI Agents", "bullet_points": ["Intelligent Virtual Agents", "Autonomous Agents", "Collaborative Agents"], "img_keywords": "AI, technology"},
+ {"heading": "Creating an AI Agent", "bullet_points": [">> Step 1: Define the goal", ">> Step 2: Choose algorithms", ">> Step 3: Implement and test"], "img_keywords": "workflow, robotics"},
+ {"heading": "Comparison of AI Agents", "table": {"headers": ["Type", "Capabilities", "Examples"], "rows": [["Virtual", "Conversational AI", "Siri"], ["Autonomous", "Self-learning", "Robots"]]}, "img_keywords": "comparison chart, table"}
+]
+```
+</details>
+
+---
+
+## 📝 Credits
+
+- Built with [CAMEL-AI](https://github.com/camel-ai/camel) (PPTXToolkit module)
+- Powered by [OpenAI](https://platform.openai.com/docs/api-reference) (for content generation)
+- Images by [Pexels](https://www.pexels.com/api/) (optional)
+- UI by [Streamlit](https://streamlit.io/)
+
+---
+
+## 🐪 License
+
+Apache 2.0
+(c) 2023-2024 [CAMEL-AI.org](https://camel-ai.org)
+
+---
+
+*Made with ❤️ by the CAMEL-AI community.*
diff --git a/examples/usecases/pptx_toolkit_usecase/app_pptx.py b/examples/usecases/pptx_toolkit_usecase/app_pptx.py
new file mode 100644
index 000000000..859985eaa
--- /dev/null
+++ b/examples/usecases/pptx_toolkit_usecase/app_pptx.py
@@ -0,0 +1,205 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+import os
+import streamlit as st
+import json
+import base64
+from typing import List, Optional, Union
+from pydantic import BaseModel, Field
+
+
+from camel.toolkits.pptx_toolkit import PPTXToolkit
+from camel.models import ModelFactory
+from camel.types import ModelPlatformType, ModelType
+from camel.agents import ChatAgent
+
+# --- Pydantic Models for Structured Output ---
+class TitleSlide(BaseModel):
+ """Title slide model"""
+ title: str = Field(description="Main title of the presentation")
+ subtitle: str = Field(description="Subtitle or description")
+
+class TableData(BaseModel):
+ """Table data model"""
+ headers: List[str] = Field(description="Table column headers")
+ rows: List[List[str]] = Field(description="Table rows data")
+
+class BulletSlide(BaseModel):
+ """Bullet point slide model"""
+ heading: str = Field(description="Slide heading")
+ bullet_points: List[str] = Field(description="List of bullet points, use >> prefix for step-by-step slides")
+ img_keywords: Optional[str] = Field(default="", description="Keywords for image search (not URLs)")
+
+class TableSlide(BaseModel):
+ """Table slide model"""
+ heading: str = Field(description="Slide heading")
+ table: TableData = Field(description="Table data with headers and rows")
+ img_keywords: Optional[str] = Field(default="", description="Keywords for image search (not URLs)")
+
+class PresentationSlides(BaseModel):
+ """Complete presentation model"""
+ title_slide: TitleSlide = Field(description="First slide must be a title slide")
+ content_slides: List[Union[BulletSlide, TableSlide]] = Field(
+ description="Content slides including bullet slides and table slides"
+ )
+
+
+# Load camel logo as base64
+def get_base64_img(path, w=32):
+ with open(path, "rb") as img_f:
+ b64 = base64.b64encode(img_f.read()).decode()
+ return f"<img src='data:image/png;base64,{b64}' width='{w}' style='vertical-align:middle;margin-bottom:4px;'>"
+
+camel_logo = get_base64_img("assets/CAMEL_logo.jpg", 40)
+
+# --- Page config ---
+st.markdown(
+ f"""
+ <div style='display:flex; align-items:center; gap:12px;'>
+ <span style="font-size:2.2rem;font-weight:700;">PPTX Generator using pptx_toolkit with</span>
+ {camel_logo}
+ </div>
+ """,
+ unsafe_allow_html=True
+)
+
+# --- Sidebar Config ---
+st.sidebar.header("⚙️ Configuration")
+openai_key = st.sidebar.text_input(
+ "OpenAI API Key (for ChatAgent/OpenAI backend)", type="password",
+ help="Get yours at https://platform.openai.com/account/api-keys"
+)
+pexels_key = st.sidebar.text_input(
+ "Pexels API Key", type="password", help="(Optional) Needed if you want images fetched from Pexels"
+)
+
+# --- User Input ---
+st.header("1. Enter Your Presentation Topic")
+topic = st.text_input("Topic (e.g., ‘Blockchain for Beginners’)")
+slide_count = st.slider("Number of slides (excluding title slide)", 3, 10, 5)
+
+# --- Construct the JSON‐generation instructions ---
+def pptx_prompt(topic: str, slide_count: int) -> str:
+ r"""Create a prompt for structured output generation"""
+ return f"""
+Create a presentation about "{topic}" with exactly {slide_count + 1} slides total (1 title slide + {slide_count} content slides).
+Requirements:
+1. First slide must be a title slide with appropriate title and subtitle
+2. Include at least one step-by-step slide (bullet points starting with ">>")
+3. Include at least one table slide with relevant data
+4. At least TWO content slides must have meaningful img_keywords for visual content
+5. Use Markdown formatting (**bold**, *italic*) in bullet points
+6. Make content clear, concise, and engaging for the topic "{topic}"
+The presentation should cover key aspects of {topic}, including practical information, processes, and relevant data.
+"""
+
+# --- Generate Slide JSON via ChatAgent ---
+def generate_pptx_json_with_agent(topic: str, slide_count: int, api_key: str):
+ # 1. Build the full instruction prompt
+ full_prompt = pptx_prompt(topic, slide_count)
+
+ # 2. Instantiate a ChatAgent pointing at OpenAI GPT-4o
+ os.environ["OPENAI_API_KEY"] = api_key
+ agent = ChatAgent(
+ system_message="You are an AI Assistant that strictly follows instructions to produce only valid JSON for slides.",
+ message_window_size=5,
+ model=ModelFactory.create(
+ model_platform=ModelPlatformType.OPENAI,
+ model_type=ModelType.GPT_4_1,
+ model_config_dict={"temperature": 0.0},
+ )
+ )
+
+ # 3. Call the agent with our instruction prompt
+ try:
+ response = agent.step(full_prompt,response_format=PresentationSlides)
+
+ # Parse JSON string into Pydantic object
+ json_content = response.msgs[0].content
+ presentation_data = PresentationSlides.model_validate_json(json_content)
+
+ # Convert to the expected JSON format
+ slides_json = []
+
+ # Add title slide
+ slides_json.append({
+ "title": presentation_data.title_slide.title,
+ "subtitle": presentation_data.title_slide.subtitle
+ })
+
+ # Add content slides
+ for slide in presentation_data.content_slides:
+ if isinstance(slide, BulletSlide):
+ slides_json.append({
+ "heading": slide.heading,
+ "bullet_points": slide.bullet_points,
+ "img_keywords": slide.img_keywords or ""
+ })
+ elif isinstance(slide, TableSlide):
+ slides_json.append({
+ "heading": slide.heading,
+ "table": {
+ "headers": slide.table.headers,
+ "rows": slide.table.rows
+ },
+ "img_keywords": slide.img_keywords or ""
+ })
+
+ return slides_json, None
+
+ except Exception as e:
+ return None, f"❌ Structured output generation failed: {e}"
+
+# --- Build & Return PPTX Bytes ---
+def build_pptx(slides):
+ os.environ["PEXELS_API_KEY"] = pexels_key or ""
+ pptx_toolkit = PPTXToolkit(output_dir="outputs")
+
+ out_name = f"demo_pptx_{abs(hash(json.dumps(slides)))}.pptx"
+ result = pptx_toolkit.create_presentation(json.dumps(slides), out_name)
+ pptx_path = os.path.join("outputs", out_name)
+ if os.path.exists(pptx_path):
+ with open(pptx_path, "rb") as f:
+ return f.read(), out_name, result
+ else:
+ return None, None, result
+
+# --- Main App Logic ---
+if not openai_key:
+ st.info("Please enter your OpenAI API key in the sidebar to continue.")
+ st.stop()
+
+if topic and st.button("Generate Presentation"):
+ st.info("🕒 Generating slide JSON with ChatAgent (GPT-4.1)...")
+ slides, error = generate_pptx_json_with_agent(topic, slide_count, openai_key)
+ if error:
+ st.error(error)
+ st.stop()
+
+ st.success("✅ Slide JSON created! Now building PPTX...")
+ pptx_bytes, fname, pptx_result = build_pptx(slides)
+
+ if pptx_bytes:
+ st.success("🎉 Your presentation is ready!")
+ st.download_button(
+ label=f"Download {fname}",
+ data=pptx_bytes,
+ file_name=fname,
+ mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
+ )
+ else:
+ st.error(f"PPTX generation failed: {pptx_result}")
+
+st.markdown("---")
+st.caption("Made with ❤️ using CAMEL-AI, OpenAI & PPTXToolkit")
\ No newline at end of file
diff --git a/examples/usecases/pptx_toolkit_usecase/assets/CAMEL_logo.jpg b/examples/usecases/pptx_toolkit_usecase/assets/CAMEL_logo.jpg
new file mode 100644
index 000000000..a6332e267
Binary files /dev/null and b/examples/usecases/pptx_toolkit_usecase/assets/CAMEL_logo.jpg differ
diff --git a/examples/usecases/pptx_toolkit_usecase/requirements.txt b/examples/usecases/pptx_toolkit_usecase/requirements.txt
new file mode 100644
index 000000000..63bfbe2f9
--- /dev/null
+++ b/examples/usecases/pptx_toolkit_usecase/requirements.txt
@@ -0,0 +1,3 @@
+camel-ai[all]==0.2.61
+streamlit
+python-pptx
\ No newline at end of file
diff --git a/examples/usecases/pptx_toolkit_usecase/slides_templates/urban_monochrome.pptx b/examples/usecases/pptx_toolkit_usecase/slides_templates/urban_monochrome.pptx
new file mode 100644
index 000000000..07384e652
Binary files /dev/null and b/examples/usecases/pptx_toolkit_usecase/slides_templates/urban_monochrome.pptx differ
diff --git a/examples/usecases/youtube_ocr/requirements.txt b/examples/usecases/youtube_ocr/requirements.txt
index e1b759b9d..c53a9809e 100644
--- a/examples/usecases/youtube_ocr/requirements.txt
+++ b/examples/usecases/youtube_ocr/requirements.txt
@@ -3,7 +3,7 @@ opencv-python==4.9.0.80
streamlit==1.45.0
pytesseract==0.3.13
streamlit==1.45.1
-camel-ai==0.2.61
+camel-ai[all]==0.2.61
python-dotenv==1.1.0
Pillow==11.2.1
git+https://github.com/openai/whisper.git