Spaces:
Running
Running
Update index.html
Browse files- index.html +39 -53
index.html
CHANGED
|
@@ -414,63 +414,49 @@
|
|
| 414 |
outputText.innerHTML = `<p class="text-gray-800 font-medium">${translatedText}</p>`;
|
| 415 |
}
|
| 416 |
});
|
|
|
|
|
|
|
|
|
|
| 417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
// Simulate translation function (in a real app, replace with API call)
|
| 419 |
function simulateTranslation(text, fromLang, toLang) {
|
| 420 |
-
// This is just a simulation - in a real app you would call a translation API
|
| 421 |
-
const translations = {
|
| 422 |
-
'en-US_es-ES': {
|
| 423 |
-
'Hello, how are you?': 'Hola, ¿cómo estás?',
|
| 424 |
-
'What time is it?': '¿Qué hora es?',
|
| 425 |
-
'Where is the bathroom?': '¿Dónde está el baño?',
|
| 426 |
-
'Thank you very much': 'Muchas gracias',
|
| 427 |
-
'I need help': 'Necesito ayuda'
|
| 428 |
-
},
|
| 429 |
-
'es-ES_en-US': {
|
| 430 |
-
'Hola, ¿cómo estás?': 'Hello, how are you?',
|
| 431 |
-
'¿Qué hora es?': 'What time is it?',
|
| 432 |
-
'¿Dónde está el baño?': 'Where is the bathroom?',
|
| 433 |
-
'Muchas gracias': 'Thank you very much',
|
| 434 |
-
'Necesito ayuda': 'I need help'
|
| 435 |
-
},
|
| 436 |
-
'en-US_fr-FR': {
|
| 437 |
-
'Hello, how are you?': 'Bonjour, comment ça va?',
|
| 438 |
-
'What time is it?': 'Quelle heure est-il?',
|
| 439 |
-
'Where is the bathroom?': 'Où sont les toilettes?',
|
| 440 |
-
'Thank you very much': 'Merci beaucoup',
|
| 441 |
-
'I need help': 'J\'ai besoin d\'aide'
|
| 442 |
-
},
|
| 443 |
-
'fr-FR_en-US': {
|
| 444 |
-
'Bonjour, comment ça va?': 'Hello, how are you?',
|
| 445 |
-
'Quelle heure est-il?': 'What time is it?',
|
| 446 |
-
'Où sont les toilettes?': 'Where is the bathroom?',
|
| 447 |
-
'Merci beaucoup': 'Thank you very much',
|
| 448 |
-
'J\'ai besoin d\'aide': 'I need help'
|
| 449 |
-
},
|
| 450 |
-
'en-US_de-DE': {
|
| 451 |
-
'Hello, how are you?': 'Hallo, wie geht es dir?',
|
| 452 |
-
'What time is it?': 'Wie spät ist es?',
|
| 453 |
-
'Where is the bathroom?': 'Wo ist die Toilette?',
|
| 454 |
-
'Thank you very much': 'Vielen Dank',
|
| 455 |
-
'I need help': 'Ich brauche Hilfe'
|
| 456 |
-
},
|
| 457 |
-
'de-DE_en-US': {
|
| 458 |
-
'Hallo, wie geht es dir?': 'Hello, how are you?',
|
| 459 |
-
'Wie spät ist es?': 'What time is it?',
|
| 460 |
-
'Wo ist die Toilette?': 'Where is the bathroom?',
|
| 461 |
-
'Vielen Dank': 'Thank you very much',
|
| 462 |
-
'Ich brauche Hilfe': 'I need help'
|
| 463 |
-
}
|
| 464 |
-
};
|
| 465 |
-
|
| 466 |
-
const langPair = `${fromLang.split('-')[0]}_${toLang.split('-')[0]}`;
|
| 467 |
-
|
| 468 |
-
if (translations[langPair] && translations[langPair][text]) {
|
| 469 |
-
return translations[langPair][text];
|
| 470 |
-
}
|
| 471 |
|
| 472 |
-
|
| 473 |
-
return
|
| 474 |
}
|
| 475 |
|
| 476 |
// Initialize voice visualizer animation
|
|
|
|
| 414 |
outputText.innerHTML = `<p class="text-gray-800 font-medium">${translatedText}</p>`;
|
| 415 |
}
|
| 416 |
});
|
| 417 |
+
async function askAzureOpenAI(prompt)
|
| 418 |
+
{
|
| 419 |
+
const endpoint = "https://lahja-dev-resource.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2023-03-15-preview";
|
| 420 |
|
| 421 |
+
try {
|
| 422 |
+
const response = await fetch(endpoint, {
|
| 423 |
+
method: "POST",
|
| 424 |
+
headers: {
|
| 425 |
+
"Content-Type": "application/json",
|
| 426 |
+
"api-key": "4AwsIf87cyBIgaJVsy0phWUQdZFcbrJxpQBDQNzL4xjcP2MFzrrYJQQJ99BIACHYHv6XJ3w3AAAAACOGYrzM"
|
| 427 |
+
},
|
| 428 |
+
body: JSON.stringify({
|
| 429 |
+
messages: [
|
| 430 |
+
{ role: "system", content: "إنت تمثل شركة أسس الذكاء الاصطناعي وترد باللهجة السعودية." },
|
| 431 |
+
{ role: "user", content: prompt }
|
| 432 |
+
]
|
| 433 |
+
}),
|
| 434 |
+
});
|
| 435 |
+
const data = await response.json();
|
| 436 |
+
return data.choices[0].message.content;
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
} catch (err) {
|
| 441 |
+
console.error("خطأ في الاتصال بـ Azure OpenAI:", err);
|
| 442 |
+
return "أعتذر، حدث خطأ أثناء معالجة طلبك.";
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
async function simulateChatGPTResponse(userInput)
|
| 446 |
+
{
|
| 447 |
+
|
| 448 |
+
conversationHistory.push({ role: 'user', content: userInput });
|
| 449 |
+
|
| 450 |
+
const response = await askAzureOpenAI(userInput);
|
| 451 |
+
return response
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
}
|
| 455 |
// Simulate translation function (in a real app, replace with API call)
|
| 456 |
function simulateTranslation(text, fromLang, toLang) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
+
|
| 459 |
+
return simulateChatGPTResponse(text)
|
| 460 |
}
|
| 461 |
|
| 462 |
// Initialize voice visualizer animation
|