Spaces:
Sleeping
Sleeping
gemin mock added
Browse files- services/gemini_service.py +30 -0
services/gemini_service.py
CHANGED
|
@@ -31,6 +31,12 @@ DOWNLOADS_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "downlo
|
|
| 31 |
# Ensure downloads directory exists
|
| 32 |
os.makedirs(DOWNLOADS_DIR, exist_ok=True)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Concurrency limits from environment (defaults)
|
| 35 |
MAX_CONCURRENT_VIDEOS = int(os.getenv("MAX_CONCURRENT_VIDEOS", "2"))
|
| 36 |
MAX_CONCURRENT_IMAGES = int(os.getenv("MAX_CONCURRENT_IMAGES", "5"))
|
|
@@ -179,6 +185,17 @@ class GeminiService:
|
|
| 179 |
Start video generation using Veo model.
|
| 180 |
Returns operation details for polling.
|
| 181 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
async with get_video_semaphore():
|
| 183 |
try:
|
| 184 |
# Start video generation
|
|
@@ -211,6 +228,19 @@ class GeminiService:
|
|
| 211 |
Check the status of a video generation operation.
|
| 212 |
Returns status and video URL if complete.
|
| 213 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
try:
|
| 215 |
# Get operation status using the operation object
|
| 216 |
# First, we need to recreate the operation from the name
|
|
|
|
| 31 |
# Ensure downloads directory exists
|
| 32 |
os.makedirs(DOWNLOADS_DIR, exist_ok=True)
|
| 33 |
|
| 34 |
+
# Mock mode for local testing (set GEMINI_MOCK_MODE=true to skip real API calls)
|
| 35 |
+
MOCK_MODE = os.getenv("GEMINI_MOCK_MODE", "false").lower() == "true"
|
| 36 |
+
|
| 37 |
+
# Sample video URL for mock mode (a public test video)
|
| 38 |
+
MOCK_VIDEO_URL = "https://video.twimg.com/amplify_video/1994083297756848128/vid/avc1/576x576/ue31qU0xts8L9tXD.mp4?tag=21"
|
| 39 |
+
|
| 40 |
# Concurrency limits from environment (defaults)
|
| 41 |
MAX_CONCURRENT_VIDEOS = int(os.getenv("MAX_CONCURRENT_VIDEOS", "2"))
|
| 42 |
MAX_CONCURRENT_IMAGES = int(os.getenv("MAX_CONCURRENT_IMAGES", "5"))
|
|
|
|
| 185 |
Start video generation using Veo model.
|
| 186 |
Returns operation details for polling.
|
| 187 |
"""
|
| 188 |
+
# Mock mode for testing without API credits
|
| 189 |
+
if MOCK_MODE:
|
| 190 |
+
import uuid
|
| 191 |
+
mock_operation_name = f"mock_operation_{uuid.uuid4().hex[:16]}"
|
| 192 |
+
logger.info(f"[MOCK MODE] Starting video generation: {mock_operation_name}")
|
| 193 |
+
return {
|
| 194 |
+
"gemini_operation_name": mock_operation_name,
|
| 195 |
+
"done": False,
|
| 196 |
+
"status": "pending"
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
async with get_video_semaphore():
|
| 200 |
try:
|
| 201 |
# Start video generation
|
|
|
|
| 228 |
Check the status of a video generation operation.
|
| 229 |
Returns status and video URL if complete.
|
| 230 |
"""
|
| 231 |
+
# Mock mode for testing without API credits
|
| 232 |
+
if MOCK_MODE:
|
| 233 |
+
# Simulate processing time: complete after 2 checks (track via a simple mechanism)
|
| 234 |
+
# For simplicity, always return completed with mock video URL
|
| 235 |
+
logger.info(f"[MOCK MODE] Checking video status: {gemini_operation_name}")
|
| 236 |
+
await asyncio.sleep(2) # Simulate API delay
|
| 237 |
+
return {
|
| 238 |
+
"gemini_operation_name": gemini_operation_name,
|
| 239 |
+
"done": True,
|
| 240 |
+
"status": "completed",
|
| 241 |
+
"video_url": MOCK_VIDEO_URL
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
try:
|
| 245 |
# Get operation status using the operation object
|
| 246 |
# First, we need to recreate the operation from the name
|