Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 10 additions & 31 deletions examples/media-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,28 @@ This package provides:

### Quick Setup

**Linux/macOS:**
**Linux (recommended):**
```bash
./setup_env.sh
```

**Windows:**
```cmd
setup_env.bat
python setup.py
```

**Manual Setup:**
```bash
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate.bat
source venv/bin/activate
pip install -r requirements.txt
cp env.example .env
```

### Environment Configuration

**Option 1: Use the setup script (recommended):**
```bash
python setup_env.py
```

**Option 2: Manual setup:**
1. **Copy the environment template:**
```bash
cp env.example .env
```

2. **Edit `.env` file with your API keys:**
```bash
# Edit .env file with your actual API keys
nano .env # or use your preferred editor
```
The setup script automatically creates a `.env` file from the template. You'll need to edit it with your actual API keys:

3. **Required API keys:**
- `OPENAI_API_KEY`: For DALL-E image generation
- `REPLICATE_API_TOKEN`: For various AI models
**Required API keys:**
- `OPENAI_API_KEY`: For DALL-E image generation
- `REPLICATE_API_TOKEN`: For various AI models

**Note:** The `.env` file is automatically ignored by git to keep your keys secure.
**Note:** The `.env` file is automatically ignored by git to keep your keys secure.

## File Structure

Expand All @@ -73,11 +54,9 @@ media-gen/
│ └── test_dummy_media_gen.py # Comprehensive tests

├── env.example # Environment variables template
├── setup_env.py # Environment setup script
├── setup.py # Unified setup script (all platforms)
├── example_usage.py # Usage examples
├── requirements.txt # Dependencies
├── setup_env.sh # Linux/macOS setup script
├── setup_env.bat # Windows setup script
├── __init__.py # Main package exports
└── README.md # This file
```
Expand Down
109 changes: 109 additions & 0 deletions examples/media-gen/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env python3
"""
Setup script for Media Generation Example (Linux).
Handles virtual environment creation and environment configuration.
"""
import subprocess
import sys

import shutil
from pathlib import Path


def run_command(
cmd: list[str], check: bool = True
) -> subprocess.CompletedProcess:
"""Run a command and return the result."""
print(f"Running: {' '.join(cmd)}")
return subprocess.run(
cmd, check=check, capture_output=True, text=True
)


def check_python_version() -> None:
"""Check if Python version is compatible."""
if sys.version_info < (3, 10):
print("Error: Python 3.10+ is required")
sys.exit(1)
version = f"{sys.version_info.major}.{sys.version_info.minor}"
print(f"✓ Python {version} detected")


def create_virtual_environment() -> None:
"""Create virtual environment."""
venv_path = Path("venv")

if venv_path.exists():
print("✓ Virtual environment already exists")
response = input("Do you want to recreate it? (y/N): ").lower()
if response == 'y':
shutil.rmtree(venv_path)
else:
return

print("Creating virtual environment...")
run_command([sys.executable, "-m", "venv", "venv"])
print("✓ Virtual environment created")


def install_requirements() -> None:
"""Install requirements in the virtual environment."""
pip_path = "venv/bin/pip"

print("Upgrading pip...")
run_command([pip_path, "install", "--upgrade", "pip"])

print("Installing requirements...")
run_command([pip_path, "install", "-r", "requirements.txt"])
print("✓ Requirements installed")


def setup_environment_file() -> None:
"""Set up the .env file from template."""
env_file = Path(".env")
example_file = Path("env.example")

if env_file.exists():
print("✓ .env file already exists")
response = input("Do you want to overwrite it? (y/N): ").lower()
if response != 'y':
return

if example_file.exists():
shutil.copy(example_file, env_file)
print("✓ Created .env file from template")
else:
print("✗ env.example file not found")
return


def main() -> None:
"""Main setup function."""
print("Media Generation Example Setup")
print("=" * 40)

# Check Python version
check_python_version()

# Create virtual environment
create_virtual_environment()

# Install requirements
install_requirements()

# Setup environment file
setup_environment_file()

print("\n✅ Setup complete!")
print("\nNext steps:")
print("1. Edit the .env file with your actual API keys")
print("2. Activate the virtual environment:")
print(" source venv/bin/activate")
print("3. Run 'python example_usage.py' to test the setup")
print("\nRequired API keys:")
print("- OPENAI_API_KEY: For DALL-E image generation")
print("- REPLICATE_API_TOKEN: For various AI models")


if __name__ == "__main__":
main()
40 changes: 0 additions & 40 deletions examples/media-gen/setup_env.bat

This file was deleted.

46 changes: 0 additions & 46 deletions examples/media-gen/setup_env.py

This file was deleted.

42 changes: 0 additions & 42 deletions examples/media-gen/setup_env.sh

This file was deleted.

Loading