Spaces:
Sleeping
Sleeping
mock
Browse files- services/gemini_service.py +25 -0
services/gemini_service.py
CHANGED
|
@@ -113,6 +113,12 @@ class GeminiService:
|
|
| 113 |
"""
|
| 114 |
Analyzes the image to generate a suitable animation prompt.
|
| 115 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
default_prompt = custom_prompt or "Describe how this image could be subtly animated with cinematic movement."
|
| 117 |
async with get_text_semaphore():
|
| 118 |
try:
|
|
@@ -143,6 +149,13 @@ class GeminiService:
|
|
| 143 |
Edit an image using Gemini image model.
|
| 144 |
Returns base64 data URI of the edited image.
|
| 145 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
async with get_image_semaphore():
|
| 147 |
try:
|
| 148 |
response = await asyncio.to_thread(
|
|
@@ -332,6 +345,12 @@ class GeminiService:
|
|
| 332 |
"""
|
| 333 |
Simple text generation with Gemini.
|
| 334 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
model_name = model or MODELS["text_generation"]
|
| 336 |
async with get_text_semaphore():
|
| 337 |
try:
|
|
@@ -355,6 +374,12 @@ class GeminiService:
|
|
| 355 |
"""
|
| 356 |
Analyze image with custom prompt.
|
| 357 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
async with get_text_semaphore():
|
| 359 |
try:
|
| 360 |
response = await asyncio.to_thread(
|
|
|
|
| 113 |
"""
|
| 114 |
Analyzes the image to generate a suitable animation prompt.
|
| 115 |
"""
|
| 116 |
+
# Mock mode for testing
|
| 117 |
+
if MOCK_MODE:
|
| 118 |
+
logger.info("[MOCK MODE] Generating animation prompt")
|
| 119 |
+
await asyncio.sleep(0.5) # Simulate API delay
|
| 120 |
+
return "A gentle breeze rustles through the scene as soft light dances across the surface. The camera slowly zooms in with a subtle parallax effect, creating depth and movement."
|
| 121 |
+
|
| 122 |
default_prompt = custom_prompt or "Describe how this image could be subtly animated with cinematic movement."
|
| 123 |
async with get_text_semaphore():
|
| 124 |
try:
|
|
|
|
| 149 |
Edit an image using Gemini image model.
|
| 150 |
Returns base64 data URI of the edited image.
|
| 151 |
"""
|
| 152 |
+
# Mock mode for testing - return a sample image
|
| 153 |
+
if MOCK_MODE:
|
| 154 |
+
logger.info(f"[MOCK MODE] Editing image with prompt: {prompt}")
|
| 155 |
+
await asyncio.sleep(1) # Simulate API delay
|
| 156 |
+
# Return a small red placeholder image (1x1 pixel)
|
| 157 |
+
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg=="
|
| 158 |
+
|
| 159 |
async with get_image_semaphore():
|
| 160 |
try:
|
| 161 |
response = await asyncio.to_thread(
|
|
|
|
| 345 |
"""
|
| 346 |
Simple text generation with Gemini.
|
| 347 |
"""
|
| 348 |
+
# Mock mode for testing
|
| 349 |
+
if MOCK_MODE:
|
| 350 |
+
logger.info(f"[MOCK MODE] Generating text for prompt: {prompt[:50]}...")
|
| 351 |
+
await asyncio.sleep(0.5) # Simulate API delay
|
| 352 |
+
return f"This is a mock response for your prompt: '{prompt[:100]}...'. In production, this would be generated by Gemini AI."
|
| 353 |
+
|
| 354 |
model_name = model or MODELS["text_generation"]
|
| 355 |
async with get_text_semaphore():
|
| 356 |
try:
|
|
|
|
| 374 |
"""
|
| 375 |
Analyze image with custom prompt.
|
| 376 |
"""
|
| 377 |
+
# Mock mode for testing
|
| 378 |
+
if MOCK_MODE:
|
| 379 |
+
logger.info(f"[MOCK MODE] Analyzing image with prompt: {prompt[:50]}...")
|
| 380 |
+
await asyncio.sleep(0.5) # Simulate API delay
|
| 381 |
+
return f"Mock analysis result: The image appears to show a scene that matches your query '{prompt[:50]}...'. This is placeholder content for testing."
|
| 382 |
+
|
| 383 |
async with get_text_semaphore():
|
| 384 |
try:
|
| 385 |
response = await asyncio.to_thread(
|