Files
eye/index.old.html
almazlar 282b5f4d19
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 51s
feat: Initialize a React application with Vite for image analysis and translation, configured with Docker and Gitea CI/CD.
2026-02-08 23:36:40 +03:00

337 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0MNNED524M"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-0MNNED524M');
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Vision</title>
<style>
:root {
--bg: #0f1117;
--card: #161b22;
--accent: #58a6ff;
--success: #238636;
--text: #c9d1d9;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
background: var(--bg);
color: var(--text);
display: flex;
justify-content: center;
padding: 20px;
line-height: 1.6;
}
.container {
background: var(--card);
padding: 2rem;
border-radius: 12px;
width: 100%;
max-width: 600px;
border: 1px solid #30363d;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
h2 {
text-align: center;
color: var(--accent);
margin-top: 0;
}
.upload-section {
border: 2px dashed #30363d;
padding: 30px;
text-align: center;
border-radius: 8px;
cursor: pointer;
transition: 0.3s;
margin-bottom: 20px;
}
.upload-section:hover {
border-color: var(--accent);
background: #1c2128;
}
#preview {
max-width: 100%;
border-radius: 8px;
margin: 15px 0;
display: none;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
button {
background: var(--accent);
color: white;
border: none;
padding: 12px;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
width: 100%;
font-size: 1rem;
transition: 0.2s;
}
button:disabled {
background: #21262d;
color: #8b949e;
cursor: not-allowed;
}
#translateBtn {
background: var(--success);
margin-top: 15px;
display: none;
}
.result-box {
margin-top: 25px;
background: #0d1117;
padding: 20px;
border-radius: 8px;
border-left: 4px solid var(--accent);
}
.label {
font-size: 0.75rem;
color: #8b949e;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
display: block;
}
#translationResult {
margin-top: 20px;
color: #acb6c2;
border-left: 4px solid var(--success);
}
.loader {
display: inline-block;
width: 12px;
height: 12px;
border: 2px solid #fff;
border-bottom-color: transparent;
border-radius: 50%;
animation: rotation 1s linear infinite;
margin-right: 8px;
}
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="container">
<h2>Bu resimde ne var?</h2>
<div class="upload-section" onclick="document.getElementById('fileInput').click()">
<p id="uploadText">📷 Görseli seçmek için buraya tıklayın</p>
<input type="file" id="fileInput" hidden accept="image/*" onchange="handlePreview(this)">
</div>
<img id="preview">
<button id="analyzeBtn" onclick="analyzeImage()" disabled>Analiz Et</button>
<div id="englishOutput" class="result-box" style="display: none;">
<span class="label">English Description</span>
<div id="resultText"></div>
<button id="translateBtn" onclick="translateText()">Türkçeye Çevir</button>
</div>
<div id="translationResult" class="result-box" style="display: none;">
<span class="label">Türkçe Çeviri</span>
<div id="trText"></div>
</div>
<button id="resetBtn" onclick="resetApp()" style="display: none; background: #30363d; margin-top: 20px;">Yeni
Analiz Başlat</button>
</div>
<script>
let base64Image = "";
let rawDescription = "";
// Görüntü seçildiğinde önizleme yap
function handlePreview(input) {
const file = input.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function (e) {
const img = new Image();
img.onload = function () {
// Resmi boyutlandıracağımız bir canvas oluşturalım
const canvas = document.createElement('canvas');
let width = img.width;
let height = img.height;
const max_size = 1024; // Maksimum genişlik/yükseklik
if (width > height) {
if (width > max_size) {
height *= max_size / width;
width = max_size;
}
} else {
if (height > max_size) {
width *= max_size / height;
height = max_size;
}
}
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, width, height);
// Küçültülmüş Base64 verisini alalım (Kalite %80)
const compressedBase64 = canvas.toDataURL('image/jpeg', 0.8);
document.getElementById('preview').src = compressedBase64;
document.getElementById('preview').style.display = "block";
base64Image = compressedBase64.split(',')[1];
document.getElementById('analyzeBtn').disabled = false;
document.getElementById('uploadText').innerText = file.name;
document.getElementById('resetBtn').style.display = "block";
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
// Moondream ile analiz yap
async function analyzeImage() {
const btn = document.getElementById('analyzeBtn');
const resultBox = document.getElementById('englishOutput');
const resultText = document.getElementById('resultText');
btn.disabled = true;
btn.innerHTML = '<span class="loader"></span> Düşünüyor...';
resultBox.style.display = "block";
resultText.innerText = "Görsel işleniyor, lütfen bekleyin...";
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.",
images: [base64Image],
stream: false
})
});
const status = response.status;
const statusText = response.statusText;
if (status === 404) {
throw new Error("Sunucu bulunamadı. Lütfen API adresini kontrol edin.");
} else if (status === 500) {
throw new Error("Sunucu hata verdi. Lütfen daha sonra tekrar deneyin.");
} else if (!response.ok) {
throw new Error(`HTTP hata: ${status} - ${statusText}`);
}
const data = await response.json();
rawDescription = data.response;
resultText.innerText = rawDescription;
document.getElementById('translateBtn').style.display = "block";
} catch (err) {
resultText.innerText = "Hata: Sunucuya ulaşılamadı. Nginx veya Ollama ayarlarını kontrol edin." + err.message;
console.error(err);
} finally {
btn.innerHTML = "Yeniden Analiz Et";
btn.disabled = false;
}
}
// Llama 3 ile çeviri yap
async function translateText() {
const transBtn = document.getElementById('translateBtn');
const trBox = document.getElementById('translationResult');
const trText = document.getElementById('trText');
transBtn.disabled = true;
transBtn.innerHTML = '<span class="loader"></span> Çevriliyor...';
trBox.style.display = "block";
trText.innerText = "Çeviri yapılıyor...";
try {
const response = await fetch('https://ai.almazlar.com/ollama/api/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: "translategemma:4b", // Burayı yeni indirdiğin modelle değiştir
prompt: `Act as a professional English-to-Turkish translator. Translate the following text into natural, fluent Turkish. Output ONLY the translation: "${rawDescription}"`,
options: {
temperature: 0.3 // Daha tutarlı ve ciddi çeviri için düşürdük
},
stream: false
})
});
const status = response.status;
const statusText = response.statusText;
if (status === 404) {
throw new Error("Sunucu bulunamadı. Lütfen API adresini kontrol edin.");
} else if (status === 500) {
throw new Error("Sunucu hata verdi. Lütfen daha sonra tekrar deneyin.");
} else if (!response.ok) {
throw new Error(`HTTP hata: ${status} - ${statusText}`);
}
const data = await response.json();
trText.innerText = data.response;
} catch (err) {
trText.innerText = "Hata: Çeviri servisi yanıt vermiyor." + err.message;
console.error(err);
} finally {
transBtn.disabled = false;
transBtn.innerHTML = "Türkçeye Çevir";
}
}
// Uygulamayı sıfırla
function resetApp() {
document.getElementById('fileInput').value = "";
document.getElementById('preview').style.display = "none";
document.getElementById('preview').src = "";
document.getElementById('englishOutput').style.display = "none";
document.getElementById('translationResult').style.display = "none";
document.getElementById('analyzeBtn').disabled = true;
document.getElementById('uploadText').innerText = "📷 Görseli seçmek için buraya tıklayın";
document.getElementById('resetBtn').style.display = "none";
base64Image = "";
rawDescription = "";
}
</script>
</body>
</html>