File size: 3,453 Bytes
5915f7c
 
 
 
 
 
 
 
 
 
534df99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71b3815
534df99
 
 
71b3815
 
 
 
 
 
534df99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: PixVerse Video Generator API
emoji: 🎬
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
license: mit
---

# PixVerse Video Generation API

FastAPI application for generating videos from images using PixVerse AI, with storage on Digital Ocean Spaces.

## Features

- **Health Check Endpoint**: `/health` - Verify service status
- **Video Generation Endpoint**: `/generate-video` - Generate video from image
- Firebase authentication
- Hugging Face token authorization
- Digital Ocean Spaces storage

## Storage Structure

```
milestone/
└── valentine/
    β”œβ”€β”€ source/     # User uploaded images
    └── results/    # Generated videos
```

## Environment Variables

Create a `.env` file with:

```env
# PixVerse API Configuration
PIXVERSE_API_KEY=your-pixverse-api-key

# Digital Ocean Spaces Configuration
DO_SPACES_KEY=your-digital-ocean-spaces-key
DO_SPACES_SECRET=your-digital-ocean-spaces-secret
DO_SPACES_BUCKET=your-bucket-name
DO_SPACES_REGION=nyc3
DO_SPACES_ENDPOINT=https://nyc3.digitaloceanspaces.com

# Firebase Configuration
FIREBASE_PROJECT_ID=your-firebase-project-id

# Hugging Face Token (for authorization)
HF_TOKEN=your-hugging-face-token
```

## Installation

```bash
pip install -r requirements.txt
```

## Running Locally

```bash
python main.py
```

Or with uvicorn:

```bash
uvicorn main:app --host 0.0.0.0 --port 7860 --reload
```

## API Endpoints

### 1. Health Check

**GET** `/health`

Response:
```json
{
    "success": true,
    "message": "Service is running",
    "data": {
        "status": "healthy",
        "service": "PixVerse Video Generation API",
        "version": "1.0.0"
    }
}
```

### 2. Generate Video

**POST** `/generate-video`

**Headers:**
- `Authorization`: `Bearer <hf_token>`

**Form Data:**
- `image`: Image file (JPG, PNG, WebP)
- `user_id`: User ID string (optional)
- `prompt_text`: Prompt text for video generation (must contain keywords to match category)
- `firebase_id_token`: Firebase ID token
- `appname`: App name for database routing (optional)

**Category Matching (4 video types):**
The prompt_text is automatically matched to one of 4 categories:
- Contains "kiss" β†’ Ai Kiss Video
- Contains "hug" β†’ Ai Hug Video
- Contains "bf" or "boyfriend" β†’ Ai BF
- Contains "gf" or "girlfriend" β†’ Ai GF

**Success Response:**
```json
{
    "success": true,
    "message": "Video created successfully",
    "data": {
        "result_url": "https://your-bucket.nyc3.digitaloceanspaces.com/milestone/valentine/results/...",
        "source_image": "https://your-bucket.nyc3.digitaloceanspaces.com/milestone/valentine/source/...",
        "video_id": 12345
    }
}
```

**Error Response:**
```json
{
    "success": false,
    "message": "Error description",
    "data": null
}
```

## Hugging Face Deployment

The API is configured to run on port 7860 for Hugging Face Spaces deployment.

### Hugging Face Secrets

Set these secrets in your Hugging Face Space:
- `PIXVERSE_API_KEY`
- `DO_SPACES_KEY`
- `DO_SPACES_SECRET`
- `DO_SPACES_BUCKET`
- `DO_SPACES_REGION`
- `DO_SPACES_ENDPOINT`
- `FIREBASE_PROJECT_ID`
- `HF_TOKEN`

## cURL Example

```bash
curl -X POST "http://localhost:7860/generate-video" \
  -H "Authorization: Bearer your-hf-token" \
  -F "image=@/path/to/image.jpg" \
  -F "user_id=user123" \
  -F "prompt_text=A romantic kiss scene with beautiful effects" \
  -F "firebase_id_token=firebase-id-token" \
  -F "appname=collage-maker"
```