Update index.html
Browse files- index.html +65 -41
index.html
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<html lang="ar" dir="rtl">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title
|
| 6 |
<style>
|
| 7 |
body { font-family: Arial; margin: 40px; }
|
| 8 |
label, button { display: block; margin-top: 15px; }
|
|
@@ -10,60 +10,84 @@
|
|
| 10 |
</style>
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
-
<h2
|
| 14 |
-
<form id="
|
| 15 |
-
<label
|
| 16 |
-
<input type="
|
| 17 |
</label>
|
| 18 |
-
<
|
|
|
|
|
|
|
|
|
|
| 19 |
</form>
|
| 20 |
<div id="result"></div>
|
| 21 |
|
| 22 |
<script>
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
event.preventDefault();
|
| 25 |
const resultDiv = document.getElementById('result');
|
| 26 |
-
resultDiv.textContent = "جاري
|
|
|
|
|
|
|
| 27 |
|
|
|
|
| 28 |
const fileInput = document.getElementById('image-input');
|
| 29 |
-
if (!fileInput.files.length) {
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
return;
|
| 32 |
}
|
| 33 |
|
| 34 |
-
//
|
| 35 |
-
const
|
| 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 |
-
resultDiv.textContent = "لم يتم التعرف على نص في الصورة.";
|
| 61 |
-
}
|
| 62 |
-
} catch (error) {
|
| 63 |
-
resultDiv.textContent = "حدث خطأ: " + error;
|
| 64 |
-
}
|
| 65 |
-
};
|
| 66 |
-
reader.readAsDataURL(file);
|
| 67 |
});
|
| 68 |
</script>
|
| 69 |
</body>
|
|
|
|
| 2 |
<html lang="ar" dir="rtl">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<title>تحليل صورة بالذكاء الاصطناعي</title>
|
| 6 |
<style>
|
| 7 |
body { font-family: Arial; margin: 40px; }
|
| 8 |
label, button { display: block; margin-top: 15px; }
|
|
|
|
| 10 |
</style>
|
| 11 |
</head>
|
| 12 |
<body>
|
| 13 |
+
<h2>تحليل صورة بالذكاء الاصطناعي</h2>
|
| 14 |
+
<form id="vision-form">
|
| 15 |
+
<label>رابط الصورة (أو ارفع صورة بالأسفل):
|
| 16 |
+
<input type="url" id="image-url" placeholder="https://example.com/image.jpg">
|
| 17 |
</label>
|
| 18 |
+
<label>أو ارفع صورة:
|
| 19 |
+
<input type="file" id="image-input" accept="image/*">
|
| 20 |
+
</label>
|
| 21 |
+
<button type="submit">حلل الصورة</button>
|
| 22 |
</form>
|
| 23 |
<div id="result"></div>
|
| 24 |
|
| 25 |
<script>
|
| 26 |
+
async function uploadToImgur(file) {
|
| 27 |
+
// رفع الصورة على Imgur للحصول على رابط مباشر
|
| 28 |
+
const formData = new FormData();
|
| 29 |
+
formData.append('image', file);
|
| 30 |
+
const res = await fetch('https://api.imgur.com/3/image', {
|
| 31 |
+
method: 'POST',
|
| 32 |
+
headers: { Authorization: 'Client-ID 54621f8d4e61e67' }, // استخدم ID مجاني من imgur.com
|
| 33 |
+
body: formData
|
| 34 |
+
});
|
| 35 |
+
const data = await res.json();
|
| 36 |
+
if (data.data && data.data.link) return data.data.link;
|
| 37 |
+
throw new Error("تعذر رفع الصورة");
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
document.getElementById('vision-form').addEventListener('submit', async function(event) {
|
| 41 |
event.preventDefault();
|
| 42 |
const resultDiv = document.getElementById('result');
|
| 43 |
+
resultDiv.textContent = "جاري التحليل...";
|
| 44 |
+
|
| 45 |
+
let imageUrl = document.getElementById('image-url').value.trim();
|
| 46 |
|
| 47 |
+
// لو مفيش رابط صورة والمستخدم رفع صورة من الجهاز
|
| 48 |
const fileInput = document.getElementById('image-input');
|
| 49 |
+
if (!imageUrl && fileInput.files.length) {
|
| 50 |
+
try {
|
| 51 |
+
imageUrl = await uploadToImgur(fileInput.files[0]);
|
| 52 |
+
} catch (err) {
|
| 53 |
+
resultDiv.textContent = "خطأ في رفع الصورة: " + err.message;
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
if (!imageUrl) {
|
| 59 |
+
resultDiv.textContent = "من فضلك ضع رابط صورة أو ارفع صورة من جهازك.";
|
| 60 |
return;
|
| 61 |
}
|
| 62 |
|
| 63 |
+
// تجهيز body بصيغة JSON
|
| 64 |
+
const body = JSON.stringify({
|
| 65 |
+
messages: [{
|
| 66 |
+
role: "user",
|
| 67 |
+
content: [
|
| 68 |
+
{ type: "text", text: "what's in the image" },
|
| 69 |
+
{ type: "image", url: imageUrl }
|
| 70 |
+
]
|
| 71 |
+
}],
|
| 72 |
+
web_access: false
|
| 73 |
+
});
|
| 74 |
|
| 75 |
+
try {
|
| 76 |
+
const response = await fetch('https://chatgpt-vision1.p.rapidapi.com/matagvision2', {
|
| 77 |
+
method: 'POST',
|
| 78 |
+
headers: {
|
| 79 |
+
'x-rapidapi-key': '091dbfbf0emsh6606eb2165cfd97p191257jsnd017aa229e09',
|
| 80 |
+
'x-rapidapi-host': 'chatgpt-vision1.p.rapidapi.com',
|
| 81 |
+
'Content-Type': 'application/json'
|
| 82 |
+
},
|
| 83 |
+
body: body
|
| 84 |
+
});
|
| 85 |
|
| 86 |
+
const data = await response.json();
|
| 87 |
+
resultDiv.textContent = JSON.stringify(data, null, 2);
|
| 88 |
+
} catch (error) {
|
| 89 |
+
resultDiv.textContent = "حدث خطأ: " + error;
|
| 90 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
});
|
| 92 |
</script>
|
| 93 |
</body>
|