feat: Initialize a React application with Vite for image analysis and translation, configured with Docker and Gitea CI/CD.
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 51s
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 51s
This commit is contained in:
53
src/services/api.js
Normal file
53
src/services/api.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const API_URL = 'https://ai.almazlar.com/ollama/api/generate';
|
||||
|
||||
export const analyzeImage = async (base64Image) => {
|
||||
try {
|
||||
const response = await fetch(API_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: "moondream",
|
||||
prompt: "Describe this image.",
|
||||
images: [base64Image],
|
||||
stream: false
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error: ${response.status} - ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.response;
|
||||
} catch (error) {
|
||||
console.error("Analysis Error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const translateText = async (text) => {
|
||||
try {
|
||||
const response = await fetch(API_URL, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: "translategemma:4b", // Using the model specified in original code
|
||||
prompt: `Act as a professional English-to-Turkish translator. Translate the following text into natural, fluent Turkish. Output ONLY the translation: "${text}"`,
|
||||
options: {
|
||||
temperature: 0.3
|
||||
},
|
||||
stream: false
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error: ${response.status} - ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data.response;
|
||||
} catch (error) {
|
||||
console.error("Translation Error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user