Spaces:
Running
Running
fix: make image generation async
Browse files
src/audio/audio_generator.py
CHANGED
|
@@ -5,7 +5,6 @@ from config import settings
|
|
| 5 |
import wave
|
| 6 |
import queue
|
| 7 |
import logging
|
| 8 |
-
import gradio as gr
|
| 9 |
import io
|
| 10 |
import time
|
| 11 |
|
|
|
|
| 5 |
import wave
|
| 6 |
import queue
|
| 7 |
import logging
|
|
|
|
| 8 |
import io
|
| 9 |
import time
|
| 10 |
|
src/images/image_generator.py
CHANGED
|
@@ -9,7 +9,7 @@ import logging
|
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
-
client = genai.Client(api_key=settings.gemini_api_key.get_secret_value())
|
| 13 |
|
| 14 |
async def generate_image(prompt: str) -> tuple[str, str] | None:
|
| 15 |
"""
|
|
@@ -26,11 +26,11 @@ async def generate_image(prompt: str) -> tuple[str, str] | None:
|
|
| 26 |
os.makedirs(output_dir, exist_ok=True)
|
| 27 |
|
| 28 |
try:
|
| 29 |
-
response = client.models.generate_content(
|
| 30 |
model="gemini-2.0-flash-preview-image-generation",
|
| 31 |
contents=prompt,
|
| 32 |
config=types.GenerateContentConfig(
|
| 33 |
-
response_modalities=['TEXT', 'IMAGE']
|
| 34 |
)
|
| 35 |
)
|
| 36 |
|
|
@@ -62,7 +62,7 @@ async def generate_image(prompt: str) -> tuple[str, str] | None:
|
|
| 62 |
return None, None
|
| 63 |
|
| 64 |
|
| 65 |
-
def modify_image(image_path: str, modification_prompt: str) -> str | None:
|
| 66 |
"""
|
| 67 |
Modify an existing image using Google's Gemini model based on a text prompt.
|
| 68 |
|
|
@@ -84,14 +84,14 @@ def modify_image(image_path: str, modification_prompt: str) -> str | None:
|
|
| 84 |
|
| 85 |
key = settings.gemini_api_key.get_secret_value()
|
| 86 |
|
| 87 |
-
client = genai.Client(api_key=key)
|
| 88 |
|
| 89 |
try:
|
| 90 |
# Load the input image
|
| 91 |
input_image = Image.open(image_path)
|
| 92 |
|
| 93 |
# Make the API call with both text and image
|
| 94 |
-
response = client.models.generate_content(
|
| 95 |
model="gemini-2.0-flash-preview-image-generation",
|
| 96 |
contents=[modification_prompt, input_image],
|
| 97 |
config=types.GenerateContentConfig(
|
|
|
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
|
| 12 |
+
client = genai.Client(api_key=settings.gemini_api_key.get_secret_value()).aio
|
| 13 |
|
| 14 |
async def generate_image(prompt: str) -> tuple[str, str] | None:
|
| 15 |
"""
|
|
|
|
| 26 |
os.makedirs(output_dir, exist_ok=True)
|
| 27 |
|
| 28 |
try:
|
| 29 |
+
response = await client.models.generate_content(
|
| 30 |
model="gemini-2.0-flash-preview-image-generation",
|
| 31 |
contents=prompt,
|
| 32 |
config=types.GenerateContentConfig(
|
| 33 |
+
response_modalities=['TEXT', 'IMAGE'],
|
| 34 |
)
|
| 35 |
)
|
| 36 |
|
|
|
|
| 62 |
return None, None
|
| 63 |
|
| 64 |
|
| 65 |
+
async def modify_image(image_path: str, modification_prompt: str) -> str | None:
|
| 66 |
"""
|
| 67 |
Modify an existing image using Google's Gemini model based on a text prompt.
|
| 68 |
|
|
|
|
| 84 |
|
| 85 |
key = settings.gemini_api_key.get_secret_value()
|
| 86 |
|
| 87 |
+
client = genai.Client(api_key=key).aio
|
| 88 |
|
| 89 |
try:
|
| 90 |
# Load the input image
|
| 91 |
input_image = Image.open(image_path)
|
| 92 |
|
| 93 |
# Make the API call with both text and image
|
| 94 |
+
response = await client.models.generate_content(
|
| 95 |
model="gemini-2.0-flash-preview-image-generation",
|
| 96 |
contents=[modification_prompt, input_image],
|
| 97 |
config=types.GenerateContentConfig(
|