65 lines
2.6 KiB
HTML
65 lines
2.6 KiB
HTML
<div id="result">Sonuç burada görünecek...</div>
|
||
<button id="translateBtn" onclick="translateText()" style="display:none; background: #28a745;">Türkçeye Çevir (Llama
|
||
3)</button>
|
||
<div id="translationResult" style="margin-top: 10px; color: #aaa; font-style: italic;"></div>
|
||
|
||
<script>
|
||
let englishDescription = "";
|
||
|
||
async function analyzeImage() {
|
||
const resultDiv = document.getElementById('result');
|
||
const transBtn = document.getElementById('translateBtn');
|
||
const transResult = document.getElementById('translationResult');
|
||
|
||
resultDiv.innerText = "Resim analiz ediliyor (Moondream)...";
|
||
transBtn.style.display = "none";
|
||
transResult.innerText = "";
|
||
|
||
try {
|
||
const response = await fetch('https://ai.almazlar.com/ollama/api/generate', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({
|
||
model: "moondream",
|
||
prompt: "Describe this image concisely in English.",
|
||
images: [base64Image],
|
||
stream: false
|
||
})
|
||
});
|
||
const data = await response.json();
|
||
englishDescription = data.response;
|
||
resultDiv.innerText = englishDescription;
|
||
|
||
// Analiz bitince çeviri butonunu göster
|
||
transBtn.style.display = "block";
|
||
} catch (err) {
|
||
resultDiv.innerText = "Hata: Analiz başarısız.";
|
||
}
|
||
}
|
||
|
||
async function translateText() {
|
||
const transResult = document.getElementById('translationResult');
|
||
const transBtn = document.getElementById('translateBtn');
|
||
|
||
transBtn.disabled = true;
|
||
transResult.innerText = "Türkçeye çevriliyor...";
|
||
|
||
try {
|
||
const response = await fetch('https://ai.almazlar.com/ollama/api/generate', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({
|
||
model: "llama3", // Veya elinizdeki diğer model: "gemma", "mistral" vb.
|
||
prompt: `Translate the following English text to Turkish. Only provide the translation, no extra comments: "${englishDescription}"`,
|
||
stream: false
|
||
})
|
||
});
|
||
const data = await response.json();
|
||
transResult.innerText = "TR: " + data.response;
|
||
} catch (err) {
|
||
transResult.innerText = "Hata: Çeviri yapılamadı.";
|
||
} finally {
|
||
transBtn.disabled = false;
|
||
}
|
||
}
|
||
</script> |