File size: 7,034 Bytes
8723cac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b9973b9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!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>