com
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package kz.konturai.parser.service;
|
||||
|
||||
import com.google.auth.oauth2.AccessToken;
|
||||
import com.google.auth.oauth2.GoogleCredentials;
|
||||
import io.netty.resolver.DefaultAddressResolverGroup;
|
||||
import org.slf4j.Logger;
|
||||
@@ -28,6 +27,7 @@ public class NanoBananaImageGenerationService implements ImageGenerationService
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NanoBananaImageGenerationService.class);
|
||||
private static final String VERTEX_API_TEMPLATE = "https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:predict";
|
||||
private static final String CREDENTIALS_FILE_PATH = "keys/google-key.json";
|
||||
|
||||
private final Semaphore semaphore = new Semaphore(1);
|
||||
private volatile long lastRequestTimestamp = 0;
|
||||
@@ -51,8 +51,6 @@ public class NanoBananaImageGenerationService implements ImageGenerationService
|
||||
@Value("${google.gemini.rateLimit.delayMs:12000}")
|
||||
private long rateLimitDelayMs;
|
||||
|
||||
private static final String CREDENTIALS_FILE_PATH = "keys/google-key.json";
|
||||
|
||||
public NanoBananaImageGenerationService() {
|
||||
HttpClient httpClient = HttpClient.create()
|
||||
.resolver(DefaultAddressResolverGroup.INSTANCE)
|
||||
@@ -83,7 +81,6 @@ public class NanoBananaImageGenerationService implements ImageGenerationService
|
||||
Thread.sleep(rateLimitDelayMs - timeSinceLast);
|
||||
}
|
||||
|
||||
// Получаем токен из файла ресурсов
|
||||
String accessToken = getAccessTokenFromResources();
|
||||
if (accessToken == null) {
|
||||
return null;
|
||||
@@ -122,12 +119,8 @@ public class NanoBananaImageGenerationService implements ImageGenerationService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Читает ключ прямо из ресурсов проекта (src/main/resources/keys/google-key.json)
|
||||
*/
|
||||
private String getAccessTokenFromResources() {
|
||||
try {
|
||||
// Загружаем файл из classpath
|
||||
ClassPathResource resource = new ClassPathResource(CREDENTIALS_FILE_PATH);
|
||||
if (!resource.exists()) {
|
||||
logger.error("Google Credentials file not found at classpath: {}", CREDENTIALS_FILE_PATH);
|
||||
@@ -157,6 +150,9 @@ public class NanoBananaImageGenerationService implements ImageGenerationService
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("sampleCount", 1);
|
||||
parameters.put("aspectRatio", "1:1");
|
||||
parameters.put("safetyFilterLevel", "block_some");
|
||||
parameters.put("personGeneration", "allow_adult");
|
||||
parameters.put("negativePrompt", "nsfw, nudity, sexual content, lgbt symbols, rainbow flags, provocative clothing, violence, gore, blood, deformed, ugly, watermark, text, signature");
|
||||
|
||||
body.put("parameters", parameters);
|
||||
return body;
|
||||
@@ -192,6 +188,7 @@ public class NanoBananaImageGenerationService implements ImageGenerationService
|
||||
}
|
||||
|
||||
private String enrichPromptForGemini(String original) {
|
||||
return "High quality, photorealistic image of: " + original;
|
||||
return "Professional, high quality, photorealistic image of: " + original +
|
||||
". Style: neutral, business-appropriate, culturally respectful.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user