azmisahin's picture
Upload 4 files
8723cac verified
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Türkçe Metin Üretici</title>
<link rel="icon" href="data:,">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f8fa;
color: #333;
}
.container {
background: white;
border-radius: 10px;
padding: 25px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #0d6efd;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
textarea, input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
}
button {
background: #0d6efd;
color: white;
border: none;
padding: 12px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
width: 100%;
transition: background 0.3s;
}
button:hover {
background: #0b5ed7;
}
button:disabled {
background: #cccccc;
cursor: not-allowed;
}
.result {
margin-top: 20px;
padding: 15px;
background: #e7f1ff;
border-radius: 5px;
min-height: 100px;
}
.loading {
display: none;
text-align: center;
margin: 20px 0;
}
.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
width: 36px;
height: 36px;
border-radius: 50%;
border-left-color: #0d6efd;
animation: spin 1s linear infinite;
margin: 0 auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.stats {
font-size: 14px;
color: #666;
margin-top: 10px;
}
.error {
color: #dc3545;
}
footer {
text-align: center;
margin-top: 30px;
color: #6c757d;
font-size: 14px;
}
.char-count {
font-size: 12px;
color: #6c757d;
text-align: right;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>Türkçe Metin Üretici</h1>
<div class="form-group">
<label for="prompt">Başlangıç Metni:</label>
<textarea id="prompt" rows="3" placeholder="Metin oluşturmak için bir başlangıç yazın...">Türkiye'nin başkenti</textarea>
<div class="char-count"><span id="char-count">0</span>/300 karakter</div>
</div>
<div class="form-group">
<label for="max-length">Maksimum Uzunluk (50-100):</label>
<input type="number" id="max-length" min="50" max="100" value="50">
</div>
<button id="generate-btn">Metin Oluştur</button>
<div class="loading" id="loading">
<div class="spinner"></div>
<p>Metin oluşturuluyor, lütfen bekleyin...</p>
</div>
<div class="result" id="result">
<p>Oluşturulan metin burada görünecek.</p>
</div>
<div class="stats" id="stats"></div>
</div>
<footer>
<p>Hugging Face Space üzerinde çalışan Türkçe Metin Üretici</p>
</footer>
<script>
const promptInput = document.getElementById('prompt');
const generateBtn = document.getElementById('generate-btn');
const loadingDiv = document.getElementById('loading');
const resultDiv = document.getElementById('result');
const statsDiv = document.getElementById('stats');
const charCountSpan = document.getElementById('char-count');
// Karakter sayacı
promptInput.addEventListener('input', function() {
const currentLength = this.value.length;
charCountSpan.textContent = currentLength;
if (currentLength > 300) {
this.value = this.value.substring(0, 300);
charCountSpan.textContent = 300;
charCountSpan.style.color = '#dc3545';
} else {
charCountSpan.style.color = '#6c757d';
}
});
// Başlangıçta karakter sayısını güncelle
charCountSpan.textContent = promptInput.value.length;
generateBtn.addEventListener('click', async () => {
const prompt = promptInput.value;
const maxLength = document.getElementById('max-length').value;
if (!prompt.trim()) {
alert('Lütfen bir başlangıç metni girin.');
return;
}
// UI güncelleme
generateBtn.disabled = true;
loadingDiv.style.display = 'block';
resultDiv.innerHTML = '<p>Oluşturulan metin burada görünecek.</p>';
statsDiv.innerText = '';
try {
const startTime = Date.now();
const response = await fetch('/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: prompt,
max_length: maxLength
})
});
const data = await response.json();
const processingTime = ((Date.now() - startTime) / 1000).toFixed(2);
if (data.success) {
resultDiv.innerHTML = `<p>${data.result}</p>`;
statsDiv.innerText = `İşlem süresi: ${processingTime} saniye`;
} else {
resultDiv.innerHTML = `<p class="error">Hata: ${data.error || 'Bilinmeyen hata'}</p>`;
}
} catch (error) {
resultDiv.innerHTML = `<p class="error">İstek gönderilirken hata oluştu: ${error.message}</p>`;
} finally {
loadingDiv.style.display = 'none';
generateBtn.disabled = false;
}
});
</script>
</body>
</html>