Spaces:
Running
Running
Update index.html
Browse files- index.html +43 -24
index.html
CHANGED
@@ -85,8 +85,7 @@
|
|
85 |
|
86 |
// Hugging Face NLI API ile çelişki tespiti
|
87 |
async function analyzeContradictionWithNLI(sentence1, sentence2, apiKey, modelName) {
|
88 |
-
const
|
89 |
-
const hypothesis = sentence2;
|
90 |
|
91 |
const response = await fetch(`https://api-inference.huggingface.co/models/${modelName}`, {
|
92 |
method: 'POST',
|
@@ -95,9 +94,9 @@
|
|
95 |
'Content-Type': 'application/json',
|
96 |
},
|
97 |
body: JSON.stringify({
|
98 |
-
inputs:
|
99 |
-
|
100 |
-
|
101 |
}
|
102 |
})
|
103 |
});
|
@@ -105,10 +104,20 @@
|
|
105 |
if (!response.ok) {
|
106 |
if (response.status === 503) {
|
107 |
// Model loading, retry after delay
|
108 |
-
|
|
|
109 |
return await analyzeContradictionWithNLI(sentence1, sentence2, apiKey, modelName);
|
110 |
}
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
|
114 |
const result = await response.json();
|
@@ -208,20 +217,26 @@
|
|
208 |
// Sonucu işle
|
209 |
let contradictionScore = 0;
|
210 |
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
const contradictionResult = result.find(r =>
|
214 |
-
r.label
|
215 |
-
r.label === 'contradiction' ||
|
216 |
-
r.label === 'CONTRADICTORY'
|
217 |
);
|
218 |
contradictionScore = contradictionResult?.score || 0;
|
219 |
-
} else if (result.
|
220 |
-
//
|
221 |
const contradictionIndex = result.labels.findIndex(label =>
|
222 |
-
label
|
223 |
-
label === 'contradiction' ||
|
224 |
-
label === 'CONTRADICTORY'
|
225 |
);
|
226 |
if (contradictionIndex !== -1) {
|
227 |
contradictionScore = result.scores[contradictionIndex];
|
@@ -230,8 +245,8 @@
|
|
230 |
|
231 |
console.log(`Analiz: "${sentence1.substring(0, 30)}..." vs "${sentence2.substring(0, 30)}..." - Çelişki: ${(contradictionScore * 100).toFixed(1)}%`);
|
232 |
|
233 |
-
// Çelişki eşiği
|
234 |
-
if (contradictionScore > 0.
|
235 |
potentialContradictions.push({
|
236 |
sentence1: sentence1,
|
237 |
sentence2: sentence2,
|
@@ -307,11 +322,11 @@
|
|
307 |
if (results.length === 0) {
|
308 |
let message = '<div style="text-align: center; padding: 20px;">';
|
309 |
message += '<h3>🎉 Analiz Tamamlandı</h3>';
|
310 |
-
message += '<p>Belirlenen eşik değerinde (%
|
311 |
message += `<div style="background-color: #f3f4f6; padding: 15px; border-radius: 5px; margin-top: 15px;">
|
312 |
<h4>${modelName} Modeli Sonucu</h4>
|
313 |
<p>Bu model özellikle çelişki tespiti için optimize edilmiştir.</p>
|
314 |
-
<p>%
|
315 |
<p>Sonuç: Metninizde güçlü çelişkiler tespit edilmemiştir.</p>
|
316 |
</div>`;
|
317 |
message += '</div>';
|
@@ -324,7 +339,7 @@
|
|
324 |
headerText = `<h3>🚨 Toplam ${totalFound} çelişki bulundu - En güçlü ${results.length} tanesi gösteriliyor:</h3>`;
|
325 |
}
|
326 |
|
327 |
-
headerText += `<p style="color: #6b7280; margin-bottom: 20px;">Model: <strong>${modelName}</strong> | Eşik: <strong>%
|
328 |
resultsDiv.innerHTML = headerText;
|
329 |
|
330 |
// Sonuçları çelişki skoruna göre sırala
|
@@ -346,10 +361,14 @@
|
|
346 |
severityColor = '#ef4444';
|
347 |
severityText = 'Yüksek';
|
348 |
bgColor = '#fef2f2';
|
349 |
-
} else if (item.contradictionScore > 0.
|
350 |
severityColor = '#f59e0b';
|
351 |
severityText = 'Orta-Yüksek';
|
352 |
bgColor = '#fef3c7';
|
|
|
|
|
|
|
|
|
353 |
}
|
354 |
|
355 |
div.style.backgroundColor = bgColor;
|
@@ -372,7 +391,7 @@
|
|
372 |
<p><strong>Gösterilen:</strong> ${results.length}</p>
|
373 |
<p><strong>En Yüksek Skor:</strong> ${(results[0].contradictionScore * 100).toFixed(1)}%</p>
|
374 |
<p style="margin-top: 15px; color: #6b7280; font-size: 14px;">
|
375 |
-
<em>Not: Çelişki skoru %
|
376 |
</p>
|
377 |
`;
|
378 |
resultsDiv.appendChild(summaryDiv);
|
|
|
85 |
|
86 |
// Hugging Face NLI API ile çelişki tespiti
|
87 |
async function analyzeContradictionWithNLI(sentence1, sentence2, apiKey, modelName) {
|
88 |
+
const inputText = `${sentence1} [SEP] ${sentence2}`;
|
|
|
89 |
|
90 |
const response = await fetch(`https://api-inference.huggingface.co/models/${modelName}`, {
|
91 |
method: 'POST',
|
|
|
94 |
'Content-Type': 'application/json',
|
95 |
},
|
96 |
body: JSON.stringify({
|
97 |
+
inputs: inputText,
|
98 |
+
parameters: {
|
99 |
+
candidate_labels: ["contradiction", "entailment", "neutral"]
|
100 |
}
|
101 |
})
|
102 |
});
|
|
|
104 |
if (!response.ok) {
|
105 |
if (response.status === 503) {
|
106 |
// Model loading, retry after delay
|
107 |
+
statusDiv.textContent = 'Model yükleniyor, lütfen bekleyin...';
|
108 |
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
109 |
return await analyzeContradictionWithNLI(sentence1, sentence2, apiKey, modelName);
|
110 |
}
|
111 |
+
|
112 |
+
// Hata detayını almak için response text'ini oku
|
113 |
+
let errorText = '';
|
114 |
+
try {
|
115 |
+
errorText = await response.text();
|
116 |
+
} catch (e) {
|
117 |
+
errorText = response.statusText;
|
118 |
+
}
|
119 |
+
|
120 |
+
throw new Error(`API Error: ${response.status} - ${errorText}`);
|
121 |
}
|
122 |
|
123 |
const result = await response.json();
|
|
|
217 |
// Sonucu işle
|
218 |
let contradictionScore = 0;
|
219 |
|
220 |
+
console.log('API Response:', result);
|
221 |
+
|
222 |
+
if (result.labels && result.scores) {
|
223 |
+
// Zero-shot classification format
|
224 |
+
const contradictionIndex = result.labels.findIndex(label =>
|
225 |
+
label.toLowerCase().includes('contradiction')
|
226 |
+
);
|
227 |
+
if (contradictionIndex !== -1) {
|
228 |
+
contradictionScore = result.scores[contradictionIndex];
|
229 |
+
}
|
230 |
+
} else if (Array.isArray(result)) {
|
231 |
+
// Array format - classification result
|
232 |
const contradictionResult = result.find(r =>
|
233 |
+
r.label && r.label.toLowerCase().includes('contradiction')
|
|
|
|
|
234 |
);
|
235 |
contradictionScore = contradictionResult?.score || 0;
|
236 |
+
} else if (result.sequence && result.labels) {
|
237 |
+
// Sequence classification format
|
238 |
const contradictionIndex = result.labels.findIndex(label =>
|
239 |
+
label.toLowerCase().includes('contradiction')
|
|
|
|
|
240 |
);
|
241 |
if (contradictionIndex !== -1) {
|
242 |
contradictionScore = result.scores[contradictionIndex];
|
|
|
245 |
|
246 |
console.log(`Analiz: "${sentence1.substring(0, 30)}..." vs "${sentence2.substring(0, 30)}..." - Çelişki: ${(contradictionScore * 100).toFixed(1)}%`);
|
247 |
|
248 |
+
// Çelişki eşiği - daha düşük bir eşik deneyelim
|
249 |
+
if (contradictionScore > 0.4) { // %40'dan yüksek çelişki skoru
|
250 |
potentialContradictions.push({
|
251 |
sentence1: sentence1,
|
252 |
sentence2: sentence2,
|
|
|
322 |
if (results.length === 0) {
|
323 |
let message = '<div style="text-align: center; padding: 20px;">';
|
324 |
message += '<h3>🎉 Analiz Tamamlandı</h3>';
|
325 |
+
message += '<p>Belirlenen eşik değerinde (%40) potansiyel çelişki bulunamadı.</p>';
|
326 |
message += `<div style="background-color: #f3f4f6; padding: 15px; border-radius: 5px; margin-top: 15px;">
|
327 |
<h4>${modelName} Modeli Sonucu</h4>
|
328 |
<p>Bu model özellikle çelişki tespiti için optimize edilmiştir.</p>
|
329 |
+
<p>%40'dan yüksek çelişki skoru aranan eşik değeridir.</p>
|
330 |
<p>Sonuç: Metninizde güçlü çelişkiler tespit edilmemiştir.</p>
|
331 |
</div>`;
|
332 |
message += '</div>';
|
|
|
339 |
headerText = `<h3>🚨 Toplam ${totalFound} çelişki bulundu - En güçlü ${results.length} tanesi gösteriliyor:</h3>`;
|
340 |
}
|
341 |
|
342 |
+
headerText += `<p style="color: #6b7280; margin-bottom: 20px;">Model: <strong>${modelName}</strong> | Eşik: <strong>%40</strong></p>`;
|
343 |
resultsDiv.innerHTML = headerText;
|
344 |
|
345 |
// Sonuçları çelişki skoruna göre sırala
|
|
|
361 |
severityColor = '#ef4444';
|
362 |
severityText = 'Yüksek';
|
363 |
bgColor = '#fef2f2';
|
364 |
+
} else if (item.contradictionScore > 0.5) {
|
365 |
severityColor = '#f59e0b';
|
366 |
severityText = 'Orta-Yüksek';
|
367 |
bgColor = '#fef3c7';
|
368 |
+
} else if (item.contradictionScore > 0.4) {
|
369 |
+
severityColor = '#eab308';
|
370 |
+
severityText = 'Orta';
|
371 |
+
bgColor = '#fefce8';
|
372 |
}
|
373 |
|
374 |
div.style.backgroundColor = bgColor;
|
|
|
391 |
<p><strong>Gösterilen:</strong> ${results.length}</p>
|
392 |
<p><strong>En Yüksek Skor:</strong> ${(results[0].contradictionScore * 100).toFixed(1)}%</p>
|
393 |
<p style="margin-top: 15px; color: #6b7280; font-size: 14px;">
|
394 |
+
<em>Not: Çelişki skoru %40'ın üzerindeki cümle çiftleri potansiyel çelişki olarak değerlendirilmiştir.</em>
|
395 |
</p>
|
396 |
`;
|
397 |
resultsDiv.appendChild(summaryDiv);
|