File size: 4,457 Bytes
5301ae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7686fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168b3d6
 
 
f7686fe
698ffee
 
5301ae9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# EMAILOUT Setup Guide

## Prerequisites

1. OpenAI API Key - Get one from https://platform.openai.com/api-keys

## Hugging Face Spaces Setup

1. **Create a new Space**:
   - Go to https://huggingface.co/spaces
   - Click "Create new Space"
   - Select "Docker" as the SDK
   - Name it "EMAILOUT" (or your preferred name)

2. **Add OpenAI API Key as Secret**:
   - Go to your Space Settings
   - Navigate to "Secrets" section
   - Add a new secret:
     - Key: `OPENAI_API_KEY`
     - Value: Your OpenAI API key

3. **Upload Files**:
   - Upload all project files to your Space
   - The Dockerfile will handle the build process

4. **Deploy**:
   - The Space will automatically build and deploy
   - Monitor the logs for any build errors

## Local Development

1. **Install Dependencies**:
   ```bash
   # Backend
   cd backend
   pip install -r requirements.txt
   
   # Frontend
   cd ../frontend
   npm install
   ```

2. **Set Environment Variables**:
   ```bash
   export OPENAI_API_KEY=your_api_key_here
   ```

   **Google Sign-In (optional)** β€” create an OAuth **Web application** client in [Google Cloud Console](https://console.cloud.google.com/apis/credentials) (APIs & Services β†’ Credentials). Under **Authorized redirect URIs** add exactly:
   - Local (Vite dev): `http://localhost:5173/api/auth/google/callback`
   - Docker / Hugging Face / your public URL: `https://<your-host>/api/auth/google/callback`

   Then set:
   ```bash
   export GOOGLE_CLIENT_ID=...
   export GOOGLE_CLIENT_SECRET=...
   # Must match the redirect URI above (recommended for dev):
   export FRONTEND_ORIGIN=http://localhost:5173
   # Or set the full callback explicitly:
   # export GOOGLE_REDIRECT_URI=http://localhost:5173/api/auth/google/callback
   # Strong random secret for signed session cookies (required in production):
   export SESSION_SECRET=$(openssl rand -hex 32)
   ```

   For **Hugging Face Spaces**, set `FRONTEND_ORIGIN` to **`https://`**, e.g. `https://your-space.hf.space` (not `http://`). Google’s OAuth policy rejects `http://` redirect URIs for public hosts; the **Authorized redirect URI** in Google Cloud must be the **https** callback, e.g. `https://your-space.hf.space/api/auth/google/callback`.

   For HTTPS deployments, also set `HTTPS_ONLY_COOKIES=1` and add your public origin to `CORS_ORIGINS` if the browser origin differs from the API host.

   **Multi-tenant / workspaces:** After sign-in, each user gets a workspace; the first user on an empty database becomes **admin** of the default workspace. Admins can **invite** others (Google accounts only) via the header; invitees open the link, then sign in with the **same email** as invited. **Smartlead webhook URL** must include your workspace id, e.g. `https://your-host/api/webhooks/smartlead?tenant_id=1` (replace `1` with your workspace id from the header switcher).

3. **Run Backend**:
   ```bash
   cd backend
   uvicorn app.main:app --reload --port 8000
   ```

4. **Run Frontend**:
   ```bash
   cd frontend
   npm run dev
   ```

## Project Structure

```
EMAILOUT/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ main.py          # FastAPI application
β”‚   β”‚   β”œβ”€β”€ database.py      # SQLite database models
β”‚   β”‚   β”œβ”€β”€ models.py         # Pydantic models
β”‚   β”‚   └── gpt_service.py   # OpenAI GPT integration
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   └── EmailSequenceGenerator.jsx
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ upload/
β”‚   β”‚   β”‚   β”œβ”€β”€ products/
β”‚   β”‚   β”‚   β”œβ”€β”€ prompts/
β”‚   β”‚   β”‚   β”œβ”€β”€ sequences/
β”‚   β”‚   β”‚   └── ui/
β”‚   β”‚   └── ...
β”‚   └── package.json
β”œβ”€β”€ Dockerfile
└── README.md
```

## Features

- βœ… CSV Upload from Apollo
- βœ… Product Selection with Custom Products
- βœ… Prompt Template Editor
- βœ… GPT-Powered Sequence Generation
- βœ… Real-time Streaming Results
- βœ… CSV Export for Klenty/Outreach

## API Endpoints

- `POST /api/upload-csv` - Upload CSV file
- `POST /api/save-prompts` - Save prompt templates
- `GET /api/generate-sequences` - Generate sequences (SSE stream)
- `GET /api/download-sequences` - Download sequences as CSV

## Database

SQLite database is stored at `/data/emailout.db` (persistent in HF Spaces).

Uploaded files are stored at `/data/uploads/`.