feat: Implement Llama 3-powered translation for image analysis descriptions and update analysis prompt.
This commit is contained in:
147
index.html
147
index.html
@@ -1,107 +1,19 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="tr">
|
|
||||||
|
|
||||||
<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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.card {
|
|
||||||
background: #1e1e1e;
|
|
||||||
padding: 2rem;
|
|
||||||
border-radius: 12px;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 500px;
|
|
||||||
text-align: center;
|
|
||||||
border: 1px solid #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
#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 id="result">Sonuç burada görünecek...</div>
|
||||||
</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>
|
<script>
|
||||||
let base64Image = "";
|
let englishDescription = "";
|
||||||
|
|
||||||
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() {
|
async function analyzeImage() {
|
||||||
const resultDiv = document.getElementById('result');
|
const resultDiv = document.getElementById('result');
|
||||||
const btn = document.getElementById('analyzeBtn');
|
const transBtn = document.getElementById('translateBtn');
|
||||||
resultDiv.innerText = "Düşünüyor...";
|
const transResult = document.getElementById('translationResult');
|
||||||
btn.disabled = true;
|
|
||||||
|
resultDiv.innerText = "Resim analiz ediliyor (Moondream)...";
|
||||||
|
transBtn.style.display = "none";
|
||||||
|
transResult.innerText = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://ai.almazlar.com/ollama/api/generate', {
|
const response = await fetch('https://ai.almazlar.com/ollama/api/generate', {
|
||||||
@@ -109,20 +21,45 @@
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: "moondream",
|
model: "moondream",
|
||||||
prompt: "Describe this image in detail.",
|
prompt: "Describe this image concisely in English.",
|
||||||
images: [base64Image],
|
images: [base64Image],
|
||||||
stream: false
|
stream: false
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
resultDiv.innerText = data.response;
|
englishDescription = data.response;
|
||||||
|
resultDiv.innerText = englishDescription;
|
||||||
|
|
||||||
|
// Analiz bitince çeviri butonunu göster
|
||||||
|
transBtn.style.display = "block";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
resultDiv.innerText = "Hata: Ollama'ya bağlanılamadı. CORS ayarlarını kontrol edin.";
|
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 {
|
} finally {
|
||||||
btn.disabled = false;
|
transBtn.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user