joermd commited on
Commit
8263469
·
verified ·
1 Parent(s): ff95748

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +261 -235
index.html CHANGED
@@ -1,242 +1,268 @@
1
  <!DOCTYPE html>
2
  <html lang="ar" dir="rtl">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>تحليل النصوص والترجمات – وضع Streaming</title>
7
- <!-- استيراد Tailwind CSS وFontAwesome -->
8
- <link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
10
- <style>
11
- /* تأثيرات الخلفية والحركة */
12
- @keyframes gradient {
13
- 0% { background-position: 0% 50%; }
14
- 50% { background-position: 100% 50%; }
15
- 100% { background-position: 0% 50%; }
16
- }
17
- .animate-gradient {
18
- background-size: 200% 200%;
19
- animation: gradient 15s ease infinite;
20
- }
21
- .transition-all { transition: all 0.3s ease-in-out; }
22
- .animate-scale { transition: transform 0.2s ease-in-out; }
23
- .animate-scale:hover { transform: scale(1.02); }
24
- .pulse-animation { animation: pulse 2s infinite; }
25
- @keyframes pulse {
26
- 0% { box-shadow: 0 0 0 0 rgba(0,0,0,0.2); }
27
- 70% { box-shadow: 0 0 0 10px rgba(0,0,0,0); }
28
- 100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); }
29
- }
30
-
31
- /* تنسيق النصوص */
32
- .text-comparison { line-height: 1.8; white-space: pre-wrap; }
33
- .highlight {
34
- color: white;
35
- background-color: #ef4444;
36
- padding: 0 3px;
37
- border-radius: 3px;
38
- font-weight: bold;
39
- }
40
-
41
- /* تقسيم الأسطر */
42
- .line-item {
43
- margin-bottom: 1rem;
44
- padding: 0.5rem;
45
- border-bottom: 1px dashed #ccc;
46
- }
47
- .line-number {
48
- font-weight: bold;
49
- color: #4B5563;
50
- margin-left: 0.5rem;
51
- }
52
- .line-text { display: inline-block; }
53
-
54
- /* تصميم البطاقات */
55
- .card {
56
- background-color: #fff;
57
- border-radius: 1rem;
58
- box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
59
- padding: 2rem;
60
- border: 1px solid #f3f4f6;
61
- }
62
- .card-hover:hover {
63
- box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2);
64
- transform: translateY(-3px);
65
- }
66
- .icon { margin-left: 0.5rem; }
67
- .upload-label {
68
- display: flex;
69
- flex-direction: row-reverse;
70
- align-items: center;
71
- justify-content: center;
72
- }
73
-
74
- /* مؤشر التحميل */
75
- .spinner {
76
- border: 4px solid #f3f3f3;
77
- border-top: 4px solid #4f46e5;
78
- border-radius: 50%;
79
- width: 40px;
80
- height: 40px;
81
- animation: spin 1s linear infinite;
82
- }
83
- @keyframes spin {
84
- 0% { transform: rotate(0deg); }
85
- 100% { transform: rotate(360deg); }
86
- }
87
-
88
- /* منطقة سلسلة التفكير */
89
- #chainOfThought {
90
- display: none;
91
- margin-top: 1rem;
92
- background-color: #f9fafb;
93
- padding: 1rem;
94
- border: 1px solid #e5e7eb;
95
- border-radius: 0.5rem;
96
- font-size: 0.9rem;
97
- direction: ltr;
98
- text-align: left;
99
- }
100
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  </head>
102
- <body class="bg-gradient-to-br from-gray-100 via-blue-100 to-indigo-100 min-h-screen">
103
- <div class="max-w-5xl mx-auto py-12">
104
- <!-- رأس الصفحة -->
105
- <header class="text-center mb-12">
106
- <h1 class="text-5xl font-bold mb-4 animate-gradient">تحليل النصوص والترجمات</h1>
107
- <p class="text-2xl">ترجم النص الهدف إلى العربية مع التعليم، ثم قارن مع النص المصدر واخرج الاختلافات (النصوص الناقصة) فقط.</p>
108
- </header>
109
-
110
- <!-- منطقة الإدخال -->
111
- <div class="space-y-6">
112
- <div>
113
- <label class="block text-2xl font-bold mb-2">النص المصدر</label>
114
- <textarea id="sourceText" class="w-full p-4 border rounded-lg" rows="6" placeholder="اكتب النص المصدر هنا..."></textarea>
115
- </div>
116
- <div>
117
- <label class="block text-2xl font-bold mb-2">النص الهدف</label>
118
- <textarea id="targetText" class="w-full p-4 border rounded-lg" rows="6" placeholder="اكتب النص الهدف هنا..."></textarea>
119
- </div>
120
- </div>
121
-
122
- <!-- زر التحليل ومؤشر التحميل -->
123
- <div class="mt-6 flex items-center justify-center space-x-4">
124
- <button id="analyzeBtn" class="px-8 py-4 bg-indigo-600 text-white font-bold rounded-lg hover:bg-indigo-700 transition">
125
- تحليل ومراجعة النصوص
126
- </button>
127
- <div id="loadingIndicator" class="spinner hidden"></div>
 
 
 
 
 
 
128
  </div>
129
 
130
- <!-- منطقة سلسلة التفكير -->
131
- <div id="chainOfThought" class="mt-6">
132
- <strong>سلسلة التفكير:</strong>
133
- <pre id="chainText" class="whitespace-pre-wrap text-gray-700"></pre>
134
- </div>
135
-
136
- <!-- منطقة النتائج -->
137
- <div id="resultSection" class="mt-8 hidden">
138
- <h2 class="text-3xl font-bold mb-4">النتائج:</h2>
139
- <div id="diffResult" class="p-4 border rounded-lg"></div>
140
- </div>
141
- </div>
142
-
143
- <script>
144
- (function(){
145
- "use strict";
146
-
147
- // برومت بسيط: ترجمة النص الهدف إلى العربية مع التعليم، ثم قارن بين النص المصدر والنص الهدف المُترجم واخرج الاختلافات (النصوص الناقصة) فقط مع وضعها بين أقواس.
148
- const PROMPT = `ترجم النص الهدف إلى العربية مع التعليم، ثم قارن بين النص المصدر والنص الهدف المُترجم واخرج الاختلافات فقط (النصوص الناقصة) مع وضعها بين أقواس ().
149
- النص المصدر:
150
- {source}
151
- النص الهدف:
152
- {target}`;
153
-
154
- // دالة عرض مؤشر التحميل
155
- const showLoading = () => {
156
- document.getElementById('loadingIndicator').classList.remove('hidden');
157
- };
158
- const hideLoading = () => {
159
- document.getElementById('loadingIndicator').classList.add('hidden');
160
- };
161
-
162
- // دالة إرسال الطلب إلى DeepSeek مع تفعيل خاصية streaming
163
- async function analyzeText(source, target) {
164
- const payload = {
165
- model: "deepseek-chat",
166
- messages: [
167
- { role: "system", content: "أنت نموذج DeepSeek؛ ترجم النص الهدف إلى العربية مع التعليم ثم قارن بينه وبين النص المصدر واخرج الاختلافات (النصوص الناقصة) فقط مع وضعها بين أقواس ()." },
168
- { role: "user", content: PROMPT.replace("{source}", source).replace("{target}", target) }
169
- ],
170
- temperature: 0.3,
171
- max_tokens: 1024,
172
- stream: true
173
- };
174
-
175
- console.log("Payload:", payload);
176
- try {
177
- const response = await fetch("https://api.deepseek.com/chat/completions", {
178
- method: "POST",
179
- headers: {
180
- "Authorization": "Bearer sk-15606736ed9e4aea8b7cc11a195d2b01",
181
- "Content-Type": "application/json"
182
- },
183
- body: JSON.stringify(payload)
184
- });
185
- if (!response.ok) {
186
- throw new Error("حدث خطأ في الاتصال: " + response.statusText);
187
- }
188
- // قراءة الاستجابة على شكل تدفق
189
- const reader = response.body.getReader();
190
- const decoder = new TextDecoder();
191
- let result = "";
192
- while (true) {
193
- const { done, value } = await reader.read();
194
- if (done) break;
195
- result += decoder.decode(value, { stream: true });
196
- // تحديث سلسلة التفكير بشكل مستمر
197
- document.getElementById('chainText').innerText = result;
198
- }
199
- return result;
200
- } catch (error) {
201
- throw error;
202
- }
203
- }
204
-
205
- // دالة بسيطة لمعالجة النتيجة: هنا نضع الاختلافات بين أقواس
206
- function processResult(source, analysisOutput) {
207
- // على سبيل المثال: افترض أن الاختلافات تظهر بين علامتي __ للنص المفقود
208
- let processed = analysisOutput.replace(/__(.*?)__/g, '<span class="highlight">($1)</span>');
209
- return processed;
210
- }
211
-
212
- // مستمع الزر
213
- document.getElementById('analyzeBtn').addEventListener('click', async () => {
214
- const sourceText = document.getElementById('sourceText').value.trim();
215
- const targetText = document.getElementById('targetText').value.trim();
216
- if (!sourceText || !targetText) {
217
- alert("يرجى إدخال كلا النصين.");
218
- return;
219
- }
220
- // إخفاء النتائج الحالية وإظهار مؤشر التحميل
221
- document.getElementById('resultSection').classList.add('hidden');
222
- document.getElementById('chainOfThought').style.display = "none";
223
- showLoading();
224
- try {
225
- const analysisOutput = await analyzeText(sourceText, targetText);
226
- // عرض سلسلة التفكير بعد استقبال البيانات
227
- document.getElementById('chainOfThought').style.display = "block";
228
- // معالجة الناتج وتطبيق التظليل
229
- const diffResult = processResult(sourceText, analysisOutput);
230
- document.getElementById('diffResult').innerHTML = diffResult;
231
- document.getElementById('resultSection').classList.remove('hidden');
232
- } catch (error) {
233
- alert("خطأ أثناء التحليل: " + error.message);
234
- } finally {
235
- hideLoading();
236
- }
237
- });
238
-
239
- })();
240
- </script>
 
 
 
 
 
241
  </body>
242
- </html>
 
1
  <!DOCTYPE html>
2
  <html lang="ar" dir="rtl">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>تطبيق مراجعة النصوص</title>
7
+ <style>
8
+ body {
9
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
10
+ line-height: 1.6;
11
+ margin: 0;
12
+ padding: 20px;
13
+ background-color: #f5f5f5;
14
+ color: #333;
15
+ }
16
+ .container {
17
+ max-width: 1200px;
18
+ margin: 0 auto;
19
+ background: white;
20
+ padding: 20px;
21
+ border-radius: 8px;
22
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
23
+ }
24
+ h1 {
25
+ color: #2c3e50;
26
+ text-align: center;
27
+ margin-bottom: 30px;
28
+ }
29
+ .text-areas {
30
+ display: flex;
31
+ flex-direction: row;
32
+ gap: 20px;
33
+ margin-bottom: 20px;
34
+ }
35
+ .text-column {
36
+ flex: 1;
37
+ display: flex;
38
+ flex-direction: column;
39
+ }
40
+ label {
41
+ font-weight: bold;
42
+ margin-bottom: 5px;
43
+ color: #2c3e50;
44
+ }
45
+ textarea {
46
+ height: 300px;
47
+ padding: 10px;
48
+ border: 1px solid #ddd;
49
+ border-radius: 4px;
50
+ resize: vertical;
51
+ font-size: 16px;
52
+ font-family: inherit;
53
+ }
54
+ button {
55
+ background-color: #3498db;
56
+ color: white;
57
+ border: none;
58
+ padding: 10px 20px;
59
+ border-radius: 4px;
60
+ cursor: pointer;
61
+ font-size: 16px;
62
+ transition: background-color 0.3s;
63
+ }
64
+ button:hover {
65
+ background-color: #2980b9;
66
+ }
67
+ .result {
68
+ margin-top: 30px;
69
+ padding: 20px;
70
+ border: 1px solid #ddd;
71
+ border-radius: 4px;
72
+ background-color: #f9f9f9;
73
+ }
74
+ .result h2 {
75
+ color: #2c3e50;
76
+ margin-top: 0;
77
+ }
78
+ .spinner {
79
+ display: none;
80
+ margin: 20px auto;
81
+ width: 50px;
82
+ height: 50px;
83
+ border: 5px solid #f3f3f3;
84
+ border-top: 5px solid #3498db;
85
+ border-radius: 50%;
86
+ animation: spin 1s linear infinite;
87
+ }
88
+ @keyframes spin {
89
+ 0% { transform: rotate(0deg); }
90
+ 100% { transform: rotate(360deg); }
91
+ }
92
+ .diff-highlight {
93
+ display: inline;
94
+ padding: 2px 0;
95
+ }
96
+ .diff-added {
97
+ background-color: #c8e6c9;
98
+ text-decoration: none;
99
+ }
100
+ .diff-removed {
101
+ background-color: #ffcdd2;
102
+ text-decoration: line-through;
103
+ }
104
+ .diff-changed {
105
+ background-color: #fff9c4;
106
+ text-decoration: none;
107
+ }
108
+ .api-key-section {
109
+ margin-bottom: 20px;
110
+ }
111
+ .error-message {
112
+ color: #e74c3c;
113
+ margin-top: 10px;
114
+ }
115
+ </style>
116
  </head>
117
+ <body>
118
+ <div class="container">
119
+ <h1>تطبيق مراجعة النصوص</h1>
120
+
121
+ <div class="api-key-section">
122
+ <label for="apiKey">مفتاح API (يمكنك تعديله إذا لزم الأمر):</label>
123
+ <input type="text" id="apiKey" value="sk-21a46269cd8e449f8aeb0cc129c36c33" style="width: 100%; padding: 8px; margin-top: 5px;">
124
+ </div>
125
+
126
+ <div class="text-areas">
127
+ <div class="text-column">
128
+ <label for="sourceText">النص المصدر (الأساسي):</label>
129
+ <textarea id="sourceText" placeholder="أدخل النص المصدر هنا..."></textarea>
130
+ </div>
131
+ <div class="text-column">
132
+ <label for="targetText">النص الهدف (المشكوك فيه):</label>
133
+ <textarea id="targetText" placeholder="أدخل النص الهدف هنا..."></textarea>
134
+ </div>
135
+ </div>
136
+
137
+ <div style="text-align: center;">
138
+ <button id="compareButton">قارن النصوص</button>
139
+ </div>
140
+
141
+ <div id="spinner" class="spinner"></div>
142
+
143
+ <div id="errorMessage" class="error-message"></div>
144
+
145
+ <div id="result" class="result" style="display: none;">
146
+ <h2>نتائج المقارنة:</h2>
147
+ <div id="comparisonResults"></div>
148
+ </div>
149
  </div>
150
 
151
+ <script>
152
+ document.getElementById('compareButton').addEventListener('click', async function() {
153
+ const sourceText = document.getElementById('sourceText').value.trim();
154
+ const targetText = document.getElementById('targetText').value.trim();
155
+ const apiKey = document.getElementById('apiKey').value.trim();
156
+ const errorMessageElement = document.getElementById('errorMessage');
157
+ const resultElement = document.getElementById('result');
158
+ const comparisonResultsElement = document.getElementById('comparisonResults');
159
+ const spinner = document.getElementById('spinner');
160
+
161
+ errorMessageElement.textContent = '';
162
+
163
+ if (!sourceText || !targetText) {
164
+ errorMessageElement.textContent = 'الرجاء إدخال كلا النصين للمقارنة';
165
+ return;
166
+ }
167
+
168
+ if (!apiKey) {
169
+ errorMessageElement.textContent = 'الرجاء إدخال مفتاح API صالح';
170
+ return;
171
+ }
172
+
173
+ spinner.style.display = 'block';
174
+ resultElement.style.display = 'none';
175
+
176
+ try {
177
+ const prompt = `
178
+ قارن بين النص المصدر والنص الهدف وحدد الاختلافات بينهما، بما في ذلك:
179
+ 1. الأرقام المكتوبة بشكل خاطئ
180
+ 2. النصوص المفقودة
181
+ 3. النصوص الفاسدة أو غير المفهومة
182
+ 4. النصوص المختلفة في المعنى
183
+
184
+ قدم تحليلاً مفصلاً للاختلافات وتصنيفها حسب نوع الخطأ.
185
+
186
+ النص المصدر:
187
+ ${sourceText}
188
+
189
+ النص الهدف:
190
+ ${targetText}
191
+ `;
192
+
193
+ const response = await fetch('https://api.deepseek.com/chat/completions', {
194
+ method: 'POST',
195
+ headers: {
196
+ 'Content-Type': 'application/json',
197
+ 'Authorization': `Bearer ${apiKey}`
198
+ },
199
+ body: JSON.stringify({
200
+ model: 'deepseek-reasoner',
201
+ messages: [
202
+ { role: 'system', content: 'أنت مساعد مفيد متخصص في مراجعة النصوص وتحديد الاختلافات بينها بدقة عالية.' },
203
+ { role: 'user', content: prompt }
204
+ ],
205
+ stream: false
206
+ })
207
+ });
208
+
209
+ if (!response.ok) {
210
+ throw new Error(`خطأ في الاتصال بالـ API: ${response.status} ${response.statusText}`);
211
+ }
212
+
213
+ const data = await response.json();
214
+ const analysisResult = data.choices[0].message.content;
215
+
216
+ comparisonResultsElement.innerHTML = formatAnalysisResult(analysisResult, sourceText, targetText);
217
+ resultElement.style.display = 'block';
218
+ } catch (error) {
219
+ errorMessageElement.textContent = `حدث خطأ: ${error.message}`;
220
+ console.error('Error:', error);
221
+ } finally {
222
+ spinner.style.display = 'none';
223
+ }
224
+ });
225
+
226
+ function formatAnalysisResult(analysisText, sourceText, targetText) {
227
+ // التحويل إلى HTML مع إبراز الاختلافات
228
+ let formattedText = analysisText
229
+ .replace(/\n/g, '<br>')
230
+ .replace(/الأرقام المكتوبة بشكل خاطئ:|الأرقام غير الصحيحة:/gi, '<strong style="color: #e74c3c;">الأرقام المكتوبة بشكل خاطئ:</strong>')
231
+ .replace(/النصوص المفقودة:/gi, '<strong style="color: #e74c3c;">النصوص المفقودة:</strong>')
232
+ .replace(/النصوص الفاسدة:|النصوص غير المفهومة:/gi, '<strong style="color: #e74c3c;">النصوص الفاسدة:</strong>')
233
+ .replace(/النصوص المختلفة في المعنى:/gi, '<strong style="color: #e74c3c;">النصوص المختلفة في المعنى:</strong>')
234
+ .replace(/في النص المصدر: "(.*?)"/g, 'في النص المصدر: "<span class="diff-highlight diff-removed">$1</span>"')
235
+ .replace(/في النص الهدف: "(.*?)"/g, 'في النص الهدف: "<span class="diff-highlight diff-added">$1</span>"');
236
+
237
+ // إضافة مقارنة نصية مرئية
238
+ const sourceLines = sourceText.split('\n');
239
+ const targetLines = targetText.split('\n');
240
+ const maxLines = Math.max(sourceLines.length, targetLines.length);
241
+
242
+ let visualComparison = '<h3>المقارنة السطرية:</h3><div style="display: flex; gap: 20px;">';
243
+
244
+ // عمود النص المصدر
245
+ visualComparison += '<div style="flex: 1;"><h4>النص المصدر:</h4><pre style="background-color: #f8f8f8; padding: 10px; border-radius: 4px; overflow-x: auto;">';
246
+ for (let i = 0; i < maxLines; i++) {
247
+ if (i < sourceLines.length) {
248
+ visualComparison += `<div>${i+1}. ${sourceLines[i] || ''}</div>`;
249
+ }
250
+ }
251
+ visualComparison += '</pre></div>';
252
+
253
+ // عمود النص الهدف
254
+ visualComparison += '<div style="flex: 1;"><h4>النص الهدف:</h4><pre style="background-color: #f8f8f8; padding: 10px; border-radius: 4px; overflow-x: auto;">';
255
+ for (let i = 0; i < maxLines; i++) {
256
+ if (i < targetLines.length) {
257
+ visualComparison += `<div>${i+1}. ${targetLines[i] || ''}</div>`;
258
+ }
259
+ }
260
+ visualComparison += '</pre></div>';
261
+
262
+ visualComparison += '</div>';
263
+
264
+ return formattedText + '<br><br>' + visualComparison;
265
+ }
266
+ </script>
267
  </body>
268
+ </html>