Amartala commited on
Commit
105f55a
·
verified ·
1 Parent(s): b8a76af

import fs from "fs";

Browse files

import fetch from "node-fetch";

// إعداد المتغيرات
const AZURE_ENDPOINT = "https://lahja-dev-resource2.openai.azure.com/openai/deployments/Wasm-V1/chat/completions?api-version=2025-01-01-preview";
const AZURE_API_KEY = "E7k8z3ADEUi2DZ1dl9pHlSTeUSoKb3jVjg5zYDAPNHBHKBfXlbTFJQQJ99BJACHYHv6XJ3w3AAAAACOGyF4Z";
const DEPLOYMENT = "Wasm-V1";
const PROMPT_MEDIA_ANALYSIS = "ضع هنا محتوى النظام لتحليل الوسائط";

// دالة لإنشاء Base64 من الصورة
function encodeImageToBase64(filePath) {
const buffer = fs.readFileSync(filePath);
const ext = filePath.split('.').pop();
return `data:image/${ext};base64,${buffer.toString('base64')}`;
}

// البيانات للإرسال
const userText = "تحليل محتوى الوسائط المرفقة";
const filePath = "./test_image.jpg"; // ضع مسار الصورة هنا
const media_url = encodeImageToBase64(filePath);

// بناء الرسائل (chat prompt)
const chat_prompt = [
{
role: "system",
content: [
{
type: "text",
text: PROMPT_MEDIA_ANALYSIS
}
]
},
{
role: "user",
content: [
{ type: "text", text: userText },
{ type: "image_url", image_url: { url: media_url } }
]
}
];

// طلب POST إلى Azure OpenAI
async function analyzeMedia() {
try {
const response = await fetch(AZURE_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json",
"api-key": AZURE_API_KEY
},
body: JSON.stringify({
model: DEPLOYMENT,
messages: chat_prompt,
max_completion_tokens: 16384,
stream: false
})
});

if (!response.ok) {
const text = await response.text();
throw new Error(`Azure API Error ${response.status}: ${text}`);
}

const data = await response.json();
console.log("Raw response:", data);
console.log("Extracted content:", data.choices[0].message.content);
} catch (err) {
console.error(err);
}
}

// نفّذ الدالة
analyzeMedia();
اربط الكود بواجهه

Files changed (2) hide show
  1. README.md +7 -4
  2. index.html +333 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Visionvortex Analyzer
3
- emoji: 🏃
4
  colorFrom: green
5
- colorTo: gray
 
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: VisionVortex Analyzer 🔍
 
3
  colorFrom: green
4
+ colorTo: green
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://deepsite.hf.co).
index.html CHANGED
@@ -1,19 +1,334 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </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>VisionVortex - تحليل الوسائط الذكي</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script src="https://unpkg.com/feather-icons"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.globe.min.js"></script>
11
+ <style>
12
+ @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');
13
+ body {
14
+ font-family: 'Tajawal', sans-serif;
15
+ }
16
+ .dropzone {
17
+ border: 2px dashed #4F46E5;
18
+ transition: all 0.3s;
19
+ }
20
+ .dropzone.active {
21
+ border-color: #10B981;
22
+ background-color: rgba(16, 185, 129, 0.05);
23
+ }
24
+ .result-card {
25
+ opacity: 0;
26
+ transform: translateY(20px);
27
+ transition: all 0.5s ease-out;
28
+ }
29
+ .result-card.show {
30
+ opacity: 1;
31
+ transform: translateY(0);
32
+ }
33
+ #vanta-bg {
34
+ position: absolute;
35
+ top: 0;
36
+ left: 0;
37
+ width: 100%;
38
+ height: 100%;
39
+ z-index: -1;
40
+ opacity: 0.3;
41
+ }
42
+ </style>
43
+ </head>
44
+ <body class="bg-gray-50 min-h-screen">
45
+ <div id="vanta-bg"></div>
46
+
47
+ <div class="container mx-auto px-4 py-12">
48
+ <!-- Header -->
49
+ <header class="text-center mb-16">
50
+ <h1 class="text-4xl md:text-5xl font-bold text-indigo-700 mb-4">VisionVortex <span class="text-emerald-500">🔍</span></h1>
51
+ <p class="text-xl text-gray-600 max-w-2xl mx-auto">أداة التحليل الذكية للوسائط المرئية باستخدام الذكاء الاصطناعي المتقدم</p>
52
+ </header>
53
+
54
+ <!-- Main Card -->
55
+ <div class="bg-white rounded-xl shadow-2xl overflow-hidden max-w-4xl mx-auto">
56
+ <!-- Upload Section -->
57
+ <div class="p-8 border-b border-gray-200">
58
+ <div class="flex flex-col md:flex-row gap-8 items-center">
59
+ <div class="flex-1">
60
+ <h2 class="text-2xl font-semibold text-gray-800 mb-4">تحميل الصورة للتحليل</h2>
61
+ <p class="text-gray-600 mb-6">اسحب وأسقط صورتك هنا أو انقر لتحديد ملف. سيتم تحليل المحتوى باستخدام نماذج الذكاء الاصطناعي المتطورة.</p>
62
+
63
+ <div id="dropzone" class="dropzone rounded-lg p-8 text-center cursor-pointer mb-6">
64
+ <i data-feather="upload-cloud" class="w-12 h-12 text-indigo-500 mx-auto mb-4"></i>
65
+ <p class="text-gray-500 mb-2">اسحب الصورة هنا أو انقر للتحميل</p>
66
+ <p class="text-sm text-gray-400">يدعم الصور: JPG, PNG, GIF (حتى 5MB)</p>
67
+ </div>
68
+ <input type="file" id="fileInput" accept="image/*" class="hidden">
69
+
70
+ <div class="flex gap-4">
71
+ <button id="analyzeBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-3 rounded-lg font-medium flex items-center gap-2 transition disabled:opacity-50 disabled:cursor-not-allowed" disabled>
72
+ <i data-feather="eye"></i>
73
+ بدء التحليل
74
+ </button>
75
+ <button id="clearBtn" class="border border-gray-300 hover:bg-gray-50 text-gray-700 px-6 py-3 rounded-lg font-medium flex items-center gap-2 transition">
76
+ <i data-feather="trash-2"></i>
77
+ مسح
78
+ </button>
79
+ </div>
80
+ </div>
81
+
82
+ <div class="flex-1">
83
+ <div class="relative bg-gray-100 rounded-lg overflow-hidden aspect-square">
84
+ <img id="previewImage" src="" alt="Preview" class="absolute inset-0 w-full h-full object-contain hidden">
85
+ <div id="emptyPreview" class="flex flex-col items-center justify-center h-full text-gray-400">
86
+ <i data-feather="image" class="w-16 h-16 mb-4"></i>
87
+ <p>ستظهر معاينة الصورة هنا</p>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ </div>
92
+ </div>
93
+
94
+ <!-- Results Section -->
95
+ <div class="p-8">
96
+ <h2 class="text-2xl font-semibold text-gray-800 mb-6">نتائج التحليل</h2>
97
+
98
+ <div id="loadingIndicator" class="hidden flex flex-col items-center py-12">
99
+ <div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-indigo-500 mb-4"></div>
100
+ <p class="text-gray-600">جاري تحليل الصورة، يرجى الانتظار...</p>
101
+ </div>
102
+
103
+ <div id="resultsContainer" class="space-y-6">
104
+ <div class="result-card bg-gray-50 p-6 rounded-xl">
105
+ <h3 class="flex items-center gap-2 text-lg font-medium text-gray-700 mb-4">
106
+ <i data-feather="info" class="text-indigo-500"></i>
107
+ ملخص التحليل
108
+ </h3>
109
+ <p id="analysisSummary" class="text-gray-600">سيعرض هنا ملخص شامل لتحليل الصورة بعد الانتهاء من المعالجة.</p>
110
+ </div>
111
+
112
+ <div class="result-card bg-gray-50 p-6 rounded-xl">
113
+ <h3 class="flex items-center gap-2 text-lg font-medium text-gray-700 mb-4">
114
+ <i data-feather="tag" class="text-emerald-500"></i>
115
+ الكلمات المفتاحية
116
+ </h3>
117
+ <div id="keywordsContainer" class="flex flex-wrap gap-2">
118
+ <span class="bg-indigo-100 text-indigo-800 px-3 py-1 rounded-full text-sm">انتظر النتائج</span>
119
+ </div>
120
+ </div>
121
+
122
+ <div class="result-card bg-gray-50 p-6 rounded-xl">
123
+ <h3 class="flex items-center gap-2 text-lg font-medium text-gray-700 mb-4">
124
+ <i data-feather="file-text" class="text-purple-500"></i>
125
+ التقرير التفصيلي
126
+ </h3>
127
+ <div id="detailedReport" class="prose max-w-none text-gray-600">
128
+ <p>سيعرض هنا التقرير التفصيلي لتحليل الصورة بعد الانتهاء من المعالجة.</p>
129
+ </div>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ </div>
134
+ </div>
135
+
136
+ <footer class="text-center py-8 mt-12 text-gray-500 text-sm">
137
+ <p>© 2023 VisionVortex. جميع الحقوق محفوظة.</p>
138
+ </footer>
139
+
140
+ <script>
141
+ feather.replace();
142
+
143
+ // Initialize Vanta.js background
144
+ VANTA.GLOBE({
145
+ el: "#vanta-bg",
146
+ mouseControls: true,
147
+ touchControls: true,
148
+ gyroControls: false,
149
+ minHeight: 200.00,
150
+ minWidth: 200.00,
151
+ scale: 1.00,
152
+ scaleMobile: 1.00,
153
+ color: 0x4f46e5,
154
+ backgroundColor: 0xf8fafc,
155
+ size: 0.8
156
+ });
157
+
158
+ // DOM elements
159
+ const dropzone = document.getElementById('dropzone');
160
+ const fileInput = document.getElementById('fileInput');
161
+ const previewImage = document.getElementById('previewImage');
162
+ const emptyPreview = document.getElementById('emptyPreview');
163
+ const analyzeBtn = document.getElementById('analyzeBtn');
164
+ const clearBtn = document.getElementById('clearBtn');
165
+ const loadingIndicator = document.getElementById('loadingIndicator');
166
+ const resultsContainer = document.getElementById('resultsContainer');
167
+ const analysisSummary = document.getElementById('analysisSummary');
168
+ const keywordsContainer = document.getElementById('keywordsContainer');
169
+ const detailedReport = document.getElementById('detailedReport');
170
+
171
+ let selectedFile = null;
172
+
173
+ // Event listeners
174
+ dropzone.addEventListener('click', () => fileInput.click());
175
+
176
+ fileInput.addEventListener('change', (e) => {
177
+ if (e.target.files.length) {
178
+ selectedFile = e.target.files[0];
179
+ displayPreview(selectedFile);
180
+ analyzeBtn.disabled = false;
181
+ }
182
+ });
183
+
184
+ dropzone.addEventListener('dragover', (e) => {
185
+ e.preventDefault();
186
+ dropzone.classList.add('active');
187
+ });
188
+
189
+ dropzone.addEventListener('dragleave', () => {
190
+ dropzone.classList.remove('active');
191
+ });
192
+
193
+ dropzone.addEventListener('drop', (e) => {
194
+ e.preventDefault();
195
+ dropzone.classList.remove('active');
196
+
197
+ if (e.dataTransfer.files.length) {
198
+ selectedFile = e.dataTransfer.files[0];
199
+ displayPreview(selectedFile);
200
+ analyzeBtn.disabled = false;
201
+ fileInput.files = e.dataTransfer.files;
202
+ }
203
+ });
204
+
205
+ clearBtn.addEventListener('click', () => {
206
+ selectedFile = null;
207
+ fileInput.value = '';
208
+ previewImage.src = '';
209
+ previewImage.classList.add('hidden');
210
+ emptyPreview.classList.remove('hidden');
211
+ analyzeBtn.disabled = true;
212
+ resetResults();
213
+ });
214
+
215
+ analyzeBtn.addEventListener('click', () => {
216
+ if (selectedFile) {
217
+ analyzeImage(selectedFile);
218
+ }
219
+ });
220
+
221
+ // Functions
222
+ function displayPreview(file) {
223
+ if (file.type.match('image.*')) {
224
+ const reader = new FileReader();
225
+
226
+ reader.onload = (e) => {
227
+ previewImage.src = e.target.result;
228
+ previewImage.classList.remove('hidden');
229
+ emptyPreview.classList.add('hidden');
230
+ };
231
+
232
+ reader.readAsDataURL(file);
233
+ }
234
+ }
235
+
236
+ function resetResults() {
237
+ analysisSummary.textContent = 'سيعرض هنا ملخص شامل لتحليل الصورة بعد الانتهاء من المعالجة.';
238
+ keywordsContainer.innerHTML = '<span class="bg-indigo-100 text-indigo-800 px-3 py-1 rounded-full text-sm">انتظر النتائج</span>';
239
+ detailedReport.innerHTML = '<p>سيعرض هنا التقرير التفصيلي لتحليل الصورة بعد الانتهاء من المعالجة.</p>';
240
+
241
+ document.querySelectorAll('.result-card').forEach(card => {
242
+ card.classList.remove('show');
243
+ });
244
+ }
245
+
246
+ function showResults() {
247
+ setTimeout(() => {
248
+ document.querySelectorAll('.result-card').forEach((card, index) => {
249
+ setTimeout(() => {
250
+ card.classList.add('show');
251
+ }, index * 200);
252
+ });
253
+ }, 300);
254
+ }
255
+
256
+ // Mock analysis function - replace with actual API call
257
+ function analyzeImage(file) {
258
+ loadingIndicator.classList.remove('hidden');
259
+ resultsContainer.classList.add('hidden');
260
+ resetResults();
261
+
262
+ // Simulate API call delay
263
+ setTimeout(() => {
264
+ loadingIndicator.classList.add('hidden');
265
+ resultsContainer.classList.remove('hidden');
266
+
267
+ // Mock results - replace with actual API response
268
+ const mockSummary = "تحليل الصورة يكشف عن مشهد طبيعي خلاب يحتوي على بحيرة صافية وجبال مغطاة بالثلوج في الخلفية. تظهر الأشجار الخضراء على جانبي البحيرة مع انعكاس واضح للمناظر الطبيعية على سطح الماء الهادئ.";
269
+
270
+ const mockKeywords = [
271
+ "مناظر طبيعية", "بحيرة", "جبال", "ثلوج",
272
+ "أشجار", "انعكاس", "سماء صافية", "هدوء"
273
+ ];
274
+
275
+ const mockReport = `
276
+ <h3>التفاصيل البصرية</h3>
277
+ <p>الصورة تلتقط مشهداً طبيعياً في وضح النهار مع إضاءة متوسطة. التركيز الأساسي على البحيرة التي تحتل الجزء الأوسط من الصورة.</p>
278
+
279
+ <h3>التركيبة اللونية</h3>
280
+ <p>يغلب على الصورة درجات اللون الأزرق والأخضر، مع وجود بقع بيضاء تمثل الثلوج على الجبال. الألوان متوازنة ومشبعة بشكل معتدل.</p>
281
+
282
+ <h3>التقييم الفني</h3>
283
+ <p>الصورة تمتلك تكويناً جيداً مع ��طوط رائدة توجه العين نحو نقطة الاهتمام الرئيسية. التباين مناسب والتفاصيل واضحة في معظم أجزاء الصورة.</p>
284
+
285
+ <h3>المشاعر المثارة</h3>
286
+ <p>المشهد يوحي بالهدوء والسكينة والجمال الطبيعي. الانعكاسات على الماء تضيف بعداً تأملياً للصورة.</p>
287
+ `;
288
+
289
+ // Update UI with mock results
290
+ analysisSummary.textContent = mockSummary;
291
+
292
+ keywordsContainer.innerHTML = '';
293
+ mockKeywords.forEach(keyword => {
294
+ const keywordElement = document.createElement('span');
295
+ keywordElement.className = 'bg-indigo-100 text-indigo-800 px-3 py-1 rounded-full text-sm';
296
+ keywordElement.textContent = keyword;
297
+ keywordsContainer.appendChild(keywordElement);
298
+ });
299
+
300
+ detailedReport.innerHTML = mockReport;
301
+
302
+ showResults();
303
+
304
+ // Scroll to results
305
+ resultsContainer.scrollIntoView({ behavior: 'smooth' });
306
+
307
+ }, 3000);
308
+ }
309
+
310
+ // Here you would integrate the actual API call from your Node.js code
311
+ /*
312
+ async function analyzeImageWithAPI(file) {
313
+ const formData = new FormData();
314
+ formData.append('image', file);
315
+
316
+ try {
317
+ const response = await fetch('/api/analyze', {
318
+ method: 'POST',
319
+ body: formData
320
+ });
321
+
322
+ const data = await response.json();
323
+ // Process the response and update UI
324
+ updateResultsUI(data);
325
+
326
+ } catch (error) {
327
+ console.error('Error analyzing image:', error);
328
+ // Show error to user
329
+ }
330
+ }
331
+ */
332
+ </script>
333
+ </body>
334
  </html>