File size: 10,909 Bytes
47b193e bc64c1b 47b193e bc64c1b 47b193e bc64c1b 47b193e bc64c1b 47b193e bc64c1b 47b193e bc64c1b 47b193e bc64c1b 47b193e bc64c1b 47b193e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>لهجة AI - مساعد باللهجة النجدية</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700&display=swap');
body {
font-family: 'Tajawal', sans-serif;
background-color: #f8f4e8;
}
.header-bg {
background: linear-gradient(135deg, #8B0000 0%, #A52A2A 100%);
}
.chat-bubble {
border-radius: 20px 20px 5px 20px;
background-color: #f0f0f0;
}
.user-bubble {
border-radius: 20px 20px 20px 5px;
background-color: #e3f2fd;
}
.audio-player {
transition: all 0.3s ease;
background-color: #fff;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.audio-player:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
</style>
</head>
<body>
<div class="min-h-screen flex flex-col">
<!-- Header -->
<header class="header-bg text-white py-6 shadow-lg">
<div class="container mx-auto px-4 text-center">
<div class="flex items-center justify-center space-x-3">
<i class="fas fa-comments text-2xl"></i>
<h1 class="text-2xl font-bold">لهجة AI</h1>
</div>
<p class="mt-2 text-sm opacity-90">
مساعد ذكي باللهجة النجدية | مطور من قبل أسس الذكاء الرقمي
</p>
</div>
</header>
<!-- Main Content -->
<main class="flex-grow container mx-auto px-4 py-8">
<div class="max-w-4xl mx-auto">
<!-- Chat Container -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<!-- Chat Messages -->
<div id="chatContainer" class="h-96 p-4 overflow-y-auto space-y-4">
<!-- Messages will be added here dynamically -->
</div>
<!-- Input Section -->
<div class="p-4 border-t border-gray-200 bg-gray-50">
<div class="flex flex-col space-y-4">
<textarea id="userInput"
class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-red-600 focus:border-red-600 outline-none transition duration-200 resize-none"
placeholder="💬 اكتب رسالتك هنا..."
rows="3"></textarea>
<div class="flex flex-col sm:flex-row items-center justify-between space-y-3 sm:space-y-0">
<div class="flex items-center space-x-3">
<div class="flex items-center">
<label for="voiceSelect" class="ml-2 text-sm font-medium text-gray-700">الصوت:</label>
<select id="voiceSelect" class="border border-gray-300 rounded-md px-3 py-1 text-sm focus:ring-red-600 focus:border-red-600 outline-none">
<option value="alloy">عادي</option>
<option value="echo">صدى</option>
<option value="nova">نوفا</option>
<option value="shimmer">شيمر</option>
</select>
</div>
<div class="flex items-center">
<label for="speedSelect" class="ml-2 text-sm font-medium text-gray-700">السرعة:</label>
<select id="speedSelect" class="border border-gray-300 rounded-md px-3 py-1 text-sm focus:ring-red-600 focus:border-red-600 outline-none">
<option value="0.8">بطيئة</option>
<option value="1.0" selected>عادية</option>
<option value="1.2">سريعة</option>
</select>
</div>
</div>
<button id="sendBtn" class="bg-red-700 hover:bg-red-800 text-white font-medium py-2 px-6 rounded-lg shadow transition duration-200 flex items-center">
<i class="fas fa-paper-plane mr-2"></i>
إرسال
</button>
</div>
</div>
</div>
</div>
<!-- Audio Players -->
<div id="audioSection" class="mt-6 grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="audio-player p-4 rounded-xl">
<h3 class="font-medium text-gray-800 mb-2">صوت السؤال</h3>
<audio id="questionAudio" controls class="w-full"></audio>
</div>
<div class="audio-player p-4 rounded-xl">
<h3 class="font-medium text-gray-800 mb-2">صوت الجواب</h3>
<audio id="answerAudio" controls class="w-full"></audio>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-gray-100 py-4 border-t border-gray-200 mt-auto">
<div class="container mx-auto px-4 text-center">
<p class="text-gray-600 text-sm">
© 2025 لهجة AI. جميع الحقوق محفوظة لشركة أسس الذكاء الرقمي.
</p>
</div>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const chatContainer = document.getElementById('chatContainer');
const userInput = document.getElementById('userInput');
const sendBtn = document.getElementById('sendBtn');
const voiceSelect = document.getElementById('voiceSelect');
const speedSelect = document.getElementById('speedSelect');
const questionAudio = document.getElementById('questionAudio');
const answerAudio = document.getElementById('answerAudio');
const audioSection = document.getElementById('audioSection');
const API_ENDPOINT = "https://your-gradio-app-url.com/api/predict"; // Replace with your Gradio API endpoint
const API_KEY = "YOUR_API_KEY_HERE"; // Replace with your actual API key
// Add message to chat
function addMessage(text, isUser) {
const messageDiv = document.createElement('div');
messageDiv.className = `flex ${isUser ? 'justify-start' : 'justify-end'}`;
const bubble = document.createElement('div');
bubble.className = isUser ? 'user-bubble p-4 max-w-xs md:max-w-md' : 'chat-bubble p-4 max-w-xs md:max-w-md';
bubble.textContent = text;
messageDiv.appendChild(bubble);
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
// Handle send button click
sendBtn.addEventListener('click', async function() {
const message = userInput.value.trim();
if (!message) return;
// Add user message
addMessage(message, true);
userInput.value = '';
// Show loading
const loadingDiv = document.createElement('div');
loadingDiv.className = 'flex justify-end';
const loadingBubble = document.createElement('div');
loadingBubble.className = 'chat-bubble p-4 max-w-xs';
loadingBubble.innerHTML = '<i class="fas fa-spinner fa-spin"></i> جاري الرد...';
loadingDiv.appendChild(loadingBubble);
chatContainer.appendChild(loadingDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
try {
// Call GPT API
const response = await fetch("https://your-gradio-app-url.com/api/predict", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
data: [
message, // user_input
voiceSelect.value, // voice
parseFloat(speedSelect.value), // speed
[], // history
API_KEY // api_key
]
})
});
const result = await response.json();
const [history, q_audio, a_audio] = result.data;
// Remove loading
chatContainer.removeChild(loadingDiv);
// Add bot response
const reply = history[history.length-1][1];
addMessage(reply, false);
// Show audio players
questionAudio.src = q_audio;
answerAudio.src = a_audio;
audioSection.classList.remove('hidden');
} catch (error) {
console.error("Error:", error);
chatContainer.removeChild(loadingDiv);
addMessage("حدث خطأ أثناء محاولة الاتصال بالخادم. الرجاء المحاولة لاحقاً.", false);
}
});
// Allow sending with Enter key
userInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendBtn.click();
}
});
});
</script>
</body>
</html> |