samtomas commited on
Commit
d80889e
·
verified ·
1 Parent(s): 8c9da22

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +117 -24
index.html CHANGED
@@ -1,29 +1,122 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
3
-
4
  <head>
5
- <meta charset="UTF-8" />
6
- <link rel="stylesheet" href="style.css" />
7
-
8
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
- <title>Transformers.js - Object Detection</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  </head>
11
-
12
  <body>
13
- <h1>Object Detection w/ 🤗 Transformers.js</h1>
14
- <label id="container" for="upload">
15
- <svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
16
- <path fill="#000"
17
- d="M3.5 24.3a3 3 0 0 1-1.9-.8c-.5-.5-.8-1.2-.8-1.9V2.9c0-.7.3-1.3.8-1.9.6-.5 1.2-.7 2-.7h18.6c.7 0 1.3.2 1.9.7.5.6.7 1.2.7 2v18.6c0 .7-.2 1.4-.7 1.9a3 3 0 0 1-2 .8H3.6Zm0-2.7h18.7V2.9H3.5v18.7Zm2.7-2.7h13.3c.3 0 .5 0 .6-.3v-.7l-3.7-5a.6.6 0 0 0-.6-.2c-.2 0-.4 0-.5.3l-3.5 4.6-2.4-3.3a.6.6 0 0 0-.6-.3c-.2 0-.4.1-.5.3l-2.7 3.6c-.1.2-.2.4 0 .7.1.2.3.3.6.3Z">
18
- </path>
19
- </svg>
20
- Click to upload image
21
- <label id="example">(or try example)</label>
22
- </label>
23
- <label id="status">Loading model...</label>
24
- <input id="upload" type="file" accept="image/*" />
25
-
26
- <script src="index.js" type="module"></script>
27
- </body>
28
 
29
- </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
+ <link href="https://googleapis.com" rel="stylesheet">
8
+ <style>
9
+ * { box-sizing: border-box; font-family: 'Cairo', sans-serif; margin: 0; padding: 0; }
10
+ body { background-color: #131314; color: #e3e3e3; display: flex; flex-direction: column; height: 100vh; }
11
+ header { background-color: #1e1f20; padding: 15px; text-align: center; font-size: 1.2rem; font-weight: bold; border-bottom: 1px solid #303132; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
12
+ .config-bar { background-color: #1e1f20; padding: 10px 20px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #303132; }
13
+ .config-bar input { flex: 1; padding: 8px 12px; background: #2b2c2d; border: 1px solid #444746; color: #fff; border-radius: 6px; outline: none; font-size: 0.9rem; text-align: left; dir: ltr; }
14
+ .chat-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; background: #131314; }
15
+ .message { max-width: 80%; padding: 12px 16px; border-radius: 12px; line-height: 1.6; word-wrap: break-word; font-size: 1rem; animation: fadeIn 0.3s ease; }
16
+ .user-message { background-color: #2b2c2d; align-self: flex-start; border-bottom-left-radius: 2px; }
17
+ .ai-message { background-color: #1a237e; align-self: flex-end; border-bottom-right-radius: 2px; }
18
+ .error-message { background-color: #b71c1c; align-self: center; border-radius: 6px; font-size: 0.9rem; }
19
+ .input-area { padding: 20px; background-color: #1e1f20; border-top: 1px solid #303132; display: flex; gap: 10px; }
20
+ .input-area textarea { flex: 1; height: 50px; padding: 12px; background: #2b2c2d; border: 1px solid #444746; color: #fff; border-radius: 8px; resize: none; outline: none; font-size: 1rem; }
21
+ .input-area button { background-color: #0b57d0; color: white; border: none; padding: 0 25px; border-radius: 8px; cursor: pointer; font-weight: bold; transition: background 0.2s; font-size: 1rem; }
22
+ .input-area button:hover { background-color: #0842a0; }
23
+ .input-area button:disabled { background-color: #444746; cursor: not-allowed; }
24
+ @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
25
+ </style>
26
  </head>
 
27
  <body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
+ <header>واجهة الشات السحابية المباشرة (Gemini)</header>
30
+
31
+ <div class="config-bar">
32
+ <label style="font-size: 0.9rem; color: #c4c7c5;">مفتاح الـ API:</label>
33
+ <input type="password" id="apiKeyInput" placeholder="أدخل مفتاح Google AI Studio API الخاص بك هنا...">
34
+ </div>
35
+
36
+ <div class="chat-container" id="chatContainer">
37
+ <div class="message ai-message">أهلاً بك! الواجهة تعمل الآن سحابياً بالكامل. يرجى إدخال مفتاح الـ API الخاص بك في الأعلى للبدء بالمحادثة.</div>
38
+ </div>
39
+
40
+ <div class="input-area">
41
+ <textarea id="userInput" placeholder="اكتب رسالتك هنا... (اضغط Enter للإرسال)" rows="1"></textarea>
42
+ <button id="sendBtn" onclick="sendMessage()">إرسال</button>
43
+ </div>
44
+
45
+ <script>
46
+ const chatContainer = document.getElementById('chatContainer');
47
+ const userInput = document.getElementById('userInput');
48
+ const apiKeyInput = document.getElementById('apiKeyInput');
49
+ const sendBtn = document.getElementById('sendBtn');
50
+
51
+ // استرجاع المفتاح تلقائياً إذا كان مخزناً في المتصفح سابقاً لحفظ وقتك
52
+ if (localStorage.getItem('gemini_api_key')) {
53
+ apiKeyInput.value = localStorage.getItem('gemini_api_key');
54
+ }
55
+
56
+ userInput.addEventListener('keydown', (e) => {
57
+ if (e.key === 'Enter' && !e.shiftKey) {
58
+ e.preventDefault();
59
+ sendMessage();
60
+ }
61
+ });
62
+
63
+ async function sendMessage() {
64
+ const text = userInput.value.trim();
65
+ const apiKey = apiKeyInput.value.trim();
66
+
67
+ if (!text) return;
68
+ if (!apiKey) {
69
+ alert('الرجاء إدخال مفتاح الـ API الخاص بـ Google AI Studio أولاً في الحقل المخصص بالأعلى!');
70
+ return;
71
+ }
72
+
73
+ // حفظ المفتاح في المتصفح محلياً لكي لا تضطر لكتابته في كل مرة تفتح السبيس
74
+ localStorage.setItem('gemini_api_key', apiKey);
75
+
76
+ // إضافة رسالة المستخدم للواجهة
77
+ appendMessage(text, 'user-message');
78
+ userInput.value = '';
79
+
80
+ // إعداد رسالة مؤقتة بانتظار الرد
81
+ const typingDiv = appendMessage('جاري التفكير وكتابة الرد...', 'ai-message');
82
+ sendBtn.disabled = true;
83
+
84
+ try {
85
+ // الاتصال المباشر والآمن بخوادم Google AI Studio من متصفحك
86
+ const response = await fetch(`https://googleapis.com{apiKey}`, {
87
+ method: 'POST',
88
+ headers: { 'Content-Type': 'application/json' },
89
+ body: JSON.stringify({
90
+ contents: [{ parts: [{ text: text }] }]
91
+ })
92
+ });
93
+
94
+ const data = await response.json();
95
+
96
+ if (!response.ok) {
97
+ throw new Error(data.error?.message || 'فشل الاتصال بالخادم، تأكد من صحة المفتاح الخاص بك.');
98
+ }
99
+
100
+ const aiResponse = data.candidates[0].content.parts[0].text;
101
+ typingDiv.innerText = aiResponse;
102
+
103
+ } catch (error) {
104
+ typingDiv.className = 'message error-message';
105
+ typingDiv.innerText = `خطأ: ${error.message}`;
106
+ } finally {
107
+ sendBtn.disabled = false;
108
+ chatContainer.scrollTop = chatContainer.scrollHeight;
109
+ }
110
+ }
111
+
112
+ function appendMessage(text, className) {
113
+ const messageDiv = document.createElement('div');
114
+ messageDiv.className = `message ${className}`;
115
+ messageDiv.innerText = text;
116
+ chatContainer.appendChild(messageDiv);
117
+ chatContainer.scrollTop = chatContainer.scrollHeight;
118
+ return messageDiv;
119
+ }
120
+ </script>
121
+ </body>
122
+ </html>