feat: Implement Llama 3-powered translation for image analysis descriptions and update analysis prompt.

This commit is contained in:
almazlar
2026-02-07 22:11:55 +03:00
parent b4734c86c9
commit 2a15c3cc3f

View File

@@ -1,128 +1,65 @@
<!DOCTYPE html>
<html lang="tr">
<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>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Görsel Analiz | Moondream</title>
<style>
body {
font-family: sans-serif;
background: #121212;
color: white;
display: flex;
justify-content: center;
padding: 20px;
<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.";
}
}
.card {
background: #1e1e1e;
padding: 2rem;
border-radius: 12px;
width: 100%;
max-width: 500px;
text-align: center;
border: 1px solid #333;
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;
}
#preview {
max-width: 100%;
border-radius: 8px;
margin-top: 15px;
display: none;
}
.upload-area {
border: 2px dashed #444;
padding: 20px;
cursor: pointer;
border-radius: 8px;
margin-bottom: 20px;
}
button {
background: #0088ff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
width: 100%;
margin-top: 10px;
}
button:disabled {
background: #444;
}
#result {
margin-top: 20px;
text-align: left;
background: #000;
padding: 15px;
border-radius: 5px;
min-height: 50px;
line-height: 1.5;
font-size: 0.9rem;
}
</style>
</head>
<body>
<div class="card">
<h2>Bu Resimde Ne Var?</h2>
<div class="upload-area" onclick="document.getElementById('fileInput').click()">
Tıkla veya Resim Yükle
<input type="file" id="fileInput" hidden accept="image/*" onchange="previewImage(this)">
</div>
<img id="preview">
<button id="analyzeBtn" onclick="analyzeImage()" disabled>Analiz Et</button>
<div id="result">Sonuç burada görünecek...</div>
</div>
<script>
let base64Image = "";
function previewImage(input) {
const file = input.files[0];
const reader = new FileReader();
reader.onload = function (e) {
const img = document.getElementById('preview');
img.src = e.target.result;
img.style.display = "block";
base64Image = e.target.result.split(',')[1];
document.getElementById('analyzeBtn').disabled = false;
};
reader.readAsDataURL(file);
}
async function analyzeImage() {
const resultDiv = document.getElementById('result');
const btn = document.getElementById('analyzeBtn');
resultDiv.innerText = "Düşünüyor...";
btn.disabled = true;
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 in detail.",
images: [base64Image],
stream: false
})
});
const data = await response.json();
resultDiv.innerText = data.response;
} catch (err) {
resultDiv.innerText = "Hata: Ollama'ya bağlanılamadı. CORS ayarlarını kontrol edin.";
} finally {
btn.disabled = false;
}
}
</script>
</body>
</html>
}
</script>