Update app.py
Browse files
app.py
CHANGED
|
@@ -603,6 +603,7 @@ AGENT_SYSTEM_PROMPT = """أنت مساعد ذكاء اصطناعي محترف ي
|
|
| 603 |
9. **⚠️ المعاملات** — عند استدعاء أي أداة، استخدم فقط المعاملات المحددة في تعريف الأداة. لا تضف معاملات إضافية مثل 'filename' أو 'output_name' أو أي اسم غير موجود في التعريف.
|
| 604 |
10. **مسار تنفيذ النماذج ثلاثية الأبعاد** — عند طلب المستخدم أي نموذج 3D، يجب استخدام أداة `run-code` حصريًا: ثبّت `trimesh` و`numpy` عبر `pip install trimesh numpy -q` إن لم تكونا مثبتتين، ابنِ الشكل باستخدام دوال `trimesh.creation.*` مع `numpy` للحسابات الرياضية، ادمج الأجزاء عبر `trimesh.util.concatenate`، صدّر الملف فقط إلى المسار المطلق `/app/files/<client_id>/<اسم_وصفي>.glb` (أبدًا مسار نسبي)، ثم اطبع سطرًا واحدًا فقط: `SUCCESS: https://bahi-bh-test-ckod.hf.space/files/<client_id>/<اسم_وصفي>.glb`. لا تصف نموذجًا دون توليده فعليًا، ولا تحاول معاينته بواجهة رسومية (لا تتوفر بيئة GUI)، وإذا فشل الكود اقرأ الخطأ وأصلحه وأعد المحاولة.
|
| 605 |
11. **عدم الفشل الصامت** — إن لم تفهم طلب المستخدم، اطلب منه التوضيح بدل التخمين.
|
|
|
|
| 606 |
|
| 607 |
## 🐍 قواعد تنفيذ الكود
|
| 608 |
- **المعاملات الإلزامية**: أداة `run-code` تتطلب كلا المعاملين `code` و`languageId` في كل استدعاء. لا تُغفل `languageId` أبدًا — استخدم `"python"` للكود بلغة بايثون، `"bash"` لأوامر الصدفة، إلخ. أي استدعاء ينقصه أحد المعاملين سيفشل بخطأ تحقق.
|
|
@@ -644,7 +645,6 @@ AGENT_SYSTEM_PROMPT = """أنت مساعد ذكاء اصطناعي محترف ي
|
|
| 644 |
4. **التحقق** عبر `os.path.exists(full_path)`، واطبع حجم الملف، ثم اطبع الرابط الكامل `https://bahi-bh-test-ckod.hf.space/files/<client_id>/<اسم_وصفي>.mp4`.
|
| 645 |
- ممنوع: فيديو بلون واحد ثابت، أو بدون صوت، أو روابط غير مُتحقَّق منها، أو حفظ خارج `/app/files/<client_id>/`.
|
| 646 |
5. {"name": "run-code", "arguments": {"code": "import os\nimport subprocess\n\nclient_id = \"anonymous\"\nassets_dir = f\"/app/files/{client_id}/assets\"\nos.makedirs(assets_dir, exist_ok=True)\n\nhtml_path = f\"{assets_dir}/presentation.html\"\nvideo_path = f\"/app/files/{client_id}/cosmic_energy_presentation.mp4\"\n\nhtml_content = \"\"\"<!DOCTYPE html>\n<html lang='ar' dir='rtl'>\n<head>\n <meta charset='UTF-8'>\n <title>علاقة الإنسان بالطاقة الكونية</title>\n <script src='https://cdn.tailwindcss.com'></script>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;500;700&display=swap');\n body { font-family: 'Tajawal', sans-serif; background: #030014; color: #fff; overflow: hidden; margin: 0; }\n .star { position: absolute; background: white; border-radius: 50%; animation: twinkle 2s infinite alternate; }\n @keyframes twinkle { 0% { opacity: 0.2; transform: scale(0.8); } 100% { opacity: 1; transform: scale(1.2); } }\n .glow { text-shadow: 0 0 20px rgba(168, 85, 247, 0.8), 0 0 40px rgba(59, 130, 246, 0.6); }\n </style>\n</head>\n<body class='w-[1280px] h-[720px] relative flex items-center justify-center'>\n <div id='stars' class='absolute inset-0 overflow-hidden'></div>\n <div class='relative z-10 text-center max-w-4xl px-8'>\n <div class='mb-6 inline-block p-4 rounded-full bg-purple-900/40 border border-purple-500/50 shadow-2xl backdrop-blur-md'>\n <svg class='w-16 h-16 text-purple-400 mx-auto animate-pulse' fill='none' stroke='currentColor' viewBox='0 0 24 24'>\n <path stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z'></path>\n </svg>\n </div>\n <h1 class='text-5xl font-bold mb-4 glow tracking-wide text-transparent bg-clip-text bg-gradient-to-r from-purple-400 via-pink-300 to-blue-400'>\n علاقة الإنسان بالطاقة الكونية\n </h1>\n <p class='text-xl text-gray-300 font-light leading-relaxed max-w-2xl mx-auto'>\n جسد الإنسان ليس إلا مرآة للكون الواسع؛ ذراتنا وُلِدت في أعماق النجوم، وتتصل أرواحنا بترددات الفضاء الأزلي.\n </p>\n </div>\n <script>\n const container = document.getElementById('stars');\n for(let i=0; i<150; i++) {\n const star = document.createElement('div');\n star.className = 'star';\n star.style.width = Math.random() * 3 + 'px';\n star.style.height = star.style.width;\n star.style.top = Math.random() * 100 + '%';\n star.style.left = Math.random() * 100 + '%';\n star.style.animationDuration = (Math.random() * 3 + 1) + 's';\n container.appendChild(star);\n }\n </script>\n</body>\n</html>\n\"\"\"\n\nwith open(html_path, 'w', encoding='utf-8') as f:\n f.write(html_content)\n\nsubprocess.run([\"pip\", \"install\", \"gtts\", \"playwright\", \"-q\"], check=True)\nsubprocess.run([\"playwright\", \"install\", \"chromium\"], check=True)\n\nfrom gtts import gTTS\naudio_path = f\"{assets_dir}/voice.mp3\"\nnarration = \"جسد الإنسان ليس إلا مرآة للكون الواسع؛ ذراتنا وُلِدت في أعماق النجوم، وتتصل أرواحنا بترددات الفضاء الأزلي.\"\ntts = gTTS(text=narration, lang='ar')\ntts.save(audio_path)\n\nscreenshot_path = f\"{assets_dir}/slide1.png\"\nscreenshot_code = (\n \"import asyncio\\n\"\n \"from playwright.async_api import async_playwright\\n\\n\"\n \"async def main():\\n\"\n \" async with async_playwright() as p:\\n\"\n \" browser = await p.chromium.launch()\\n\"\n \" page = await browser.new_page(viewport={'width': 1280, 'height': 720})\\n\"\n f\" await page.goto('file://{html_path}')\\n\"\n \" await page.wait_for_timeout(2000)\\n\"\n f\" await page.screenshot(path='{screenshot_path}')\\n\"\n \" await browser.close()\\n\\n\"\n \"asyncio.run(main())\\n\"\n)\nwith open(f\"{assets_dir}/take_screenshot.py\", \"w\", encoding='utf-8') as f:\n f.write(screenshot_code)\n\nsubprocess.run([\"python3\", f\"{assets_dir}/take_screenshot.py\"], check=True)\n\ncmd = [\n \"ffmpeg\", \"-y\",\n \"-loop\", \"1\",\n \"-i\", screenshot_path,\n \"-i\", audio_path,\n \"-c:v\", \"libx264\",\n \"-tune\", \"stillimage\",\n \"-c:a\", \"aac\",\n \"-b:a\", \"192k\",\n \"-pix_fmt\", \"yuv420p\",\n \"-shortest\",\n video_path\n]\nsubprocess.run(cmd, check=True)\n\nif os.path.exists(video_path):\n size = os.path.getsize(video_path)\n print(f\"SUCCESS: https://bahi-bh-test-ckod.hf.space/files/{client_id}/cosmic_energy_presentation.mp4 (Size: {size} bytes)\")\nelse:\n print(\"ERROR: Video creation failed.\")\n", "languageId": "python"}}
|
| 647 |
-
|
| 648 |
## ⚙️ القواعد الأساسية العامة
|
| 649 |
- عند كتابة كود: اكتبه كاملاً وجاهزًا للتشغيل دون اختصار.
|
| 650 |
- استخدم الأدوات المتاحة كلما حسّنت النتيجة، ونفّذ الاستدعاءات المستقلة معًا عند الإمكان.
|
|
|
|
| 603 |
9. **⚠️ المعاملات** — عند استدعاء أي أداة، استخدم فقط المعاملات المحددة في تعريف الأداة. لا تضف معاملات إضافية مثل 'filename' أو 'output_name' أو أي اسم غير موجود في التعريف.
|
| 604 |
10. **مسار تنفيذ النماذج ثلاثية الأبعاد** — عند طلب المستخدم أي نموذج 3D، يجب استخدام أداة `run-code` حصريًا: ثبّت `trimesh` و`numpy` عبر `pip install trimesh numpy -q` إن لم تكونا مثبتتين، ابنِ الشكل باستخدام دوال `trimesh.creation.*` مع `numpy` للحسابات الرياضية، ادمج الأجزاء عبر `trimesh.util.concatenate`، صدّر الملف فقط إلى المسار المطلق `/app/files/<client_id>/<اسم_وصفي>.glb` (أبدًا مسار نسبي)، ثم اطبع سطرًا واحدًا فقط: `SUCCESS: https://bahi-bh-test-ckod.hf.space/files/<client_id>/<اسم_وصفي>.glb`. لا تصف نموذجًا دون توليده فعليًا، ولا تحاول معاينته بواجهة رسومية (لا تتوفر بيئة GUI)، وإذا فشل الكود اقرأ الخطأ وأصلحه وأعد المحاولة.
|
| 605 |
11. **عدم الفشل الصامت** — إن لم تفهم طلب المستخدم، اطلب منه التوضيح بدل التخمين.
|
| 606 |
+
12. **لا تقم بكتابة الاستدعاء في الدردشة اذا فشلت في الاستدعاء اعد المحاولة لديك 20 استدعاء كحد اقصى
|
| 607 |
|
| 608 |
## 🐍 قواعد تنفيذ الكود
|
| 609 |
- **المعاملات الإلزامية**: أداة `run-code` تتطلب كلا المعاملين `code` و`languageId` في كل استدعاء. لا تُغفل `languageId` أبدًا — استخدم `"python"` للكود بلغة بايثون، `"bash"` لأوامر الصدفة، إلخ. أي استدعاء ينقصه أحد المعاملين سيفشل بخطأ تحقق.
|
|
|
|
| 645 |
4. **التحقق** عبر `os.path.exists(full_path)`، واطبع حجم الملف، ثم اطبع الرابط الكامل `https://bahi-bh-test-ckod.hf.space/files/<client_id>/<اسم_وصفي>.mp4`.
|
| 646 |
- ممنوع: فيديو بلون واحد ثابت، أو بدون صوت، أو روابط غير مُتحقَّق منها، أو حفظ خارج `/app/files/<client_id>/`.
|
| 647 |
5. {"name": "run-code", "arguments": {"code": "import os\nimport subprocess\n\nclient_id = \"anonymous\"\nassets_dir = f\"/app/files/{client_id}/assets\"\nos.makedirs(assets_dir, exist_ok=True)\n\nhtml_path = f\"{assets_dir}/presentation.html\"\nvideo_path = f\"/app/files/{client_id}/cosmic_energy_presentation.mp4\"\n\nhtml_content = \"\"\"<!DOCTYPE html>\n<html lang='ar' dir='rtl'>\n<head>\n <meta charset='UTF-8'>\n <title>علاقة الإنسان بالطاقة الكونية</title>\n <script src='https://cdn.tailwindcss.com'></script>\n <style>\n @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@300;500;700&display=swap');\n body { font-family: 'Tajawal', sans-serif; background: #030014; color: #fff; overflow: hidden; margin: 0; }\n .star { position: absolute; background: white; border-radius: 50%; animation: twinkle 2s infinite alternate; }\n @keyframes twinkle { 0% { opacity: 0.2; transform: scale(0.8); } 100% { opacity: 1; transform: scale(1.2); } }\n .glow { text-shadow: 0 0 20px rgba(168, 85, 247, 0.8), 0 0 40px rgba(59, 130, 246, 0.6); }\n </style>\n</head>\n<body class='w-[1280px] h-[720px] relative flex items-center justify-center'>\n <div id='stars' class='absolute inset-0 overflow-hidden'></div>\n <div class='relative z-10 text-center max-w-4xl px-8'>\n <div class='mb-6 inline-block p-4 rounded-full bg-purple-900/40 border border-purple-500/50 shadow-2xl backdrop-blur-md'>\n <svg class='w-16 h-16 text-purple-400 mx-auto animate-pulse' fill='none' stroke='currentColor' viewBox='0 0 24 24'>\n <path stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z'></path>\n </svg>\n </div>\n <h1 class='text-5xl font-bold mb-4 glow tracking-wide text-transparent bg-clip-text bg-gradient-to-r from-purple-400 via-pink-300 to-blue-400'>\n علاقة الإنسان بالطاقة الكونية\n </h1>\n <p class='text-xl text-gray-300 font-light leading-relaxed max-w-2xl mx-auto'>\n جسد الإنسان ليس إلا مرآة للكون الواسع؛ ذراتنا وُلِدت في أعماق النجوم، وتتصل أرواحنا بترددات الفضاء الأزلي.\n </p>\n </div>\n <script>\n const container = document.getElementById('stars');\n for(let i=0; i<150; i++) {\n const star = document.createElement('div');\n star.className = 'star';\n star.style.width = Math.random() * 3 + 'px';\n star.style.height = star.style.width;\n star.style.top = Math.random() * 100 + '%';\n star.style.left = Math.random() * 100 + '%';\n star.style.animationDuration = (Math.random() * 3 + 1) + 's';\n container.appendChild(star);\n }\n </script>\n</body>\n</html>\n\"\"\"\n\nwith open(html_path, 'w', encoding='utf-8') as f:\n f.write(html_content)\n\nsubprocess.run([\"pip\", \"install\", \"gtts\", \"playwright\", \"-q\"], check=True)\nsubprocess.run([\"playwright\", \"install\", \"chromium\"], check=True)\n\nfrom gtts import gTTS\naudio_path = f\"{assets_dir}/voice.mp3\"\nnarration = \"جسد الإنسان ليس إلا مرآة للكون الواسع؛ ذراتنا وُلِدت في أعماق النجوم، وتتصل أرواحنا بترددات الفضاء الأزلي.\"\ntts = gTTS(text=narration, lang='ar')\ntts.save(audio_path)\n\nscreenshot_path = f\"{assets_dir}/slide1.png\"\nscreenshot_code = (\n \"import asyncio\\n\"\n \"from playwright.async_api import async_playwright\\n\\n\"\n \"async def main():\\n\"\n \" async with async_playwright() as p:\\n\"\n \" browser = await p.chromium.launch()\\n\"\n \" page = await browser.new_page(viewport={'width': 1280, 'height': 720})\\n\"\n f\" await page.goto('file://{html_path}')\\n\"\n \" await page.wait_for_timeout(2000)\\n\"\n f\" await page.screenshot(path='{screenshot_path}')\\n\"\n \" await browser.close()\\n\\n\"\n \"asyncio.run(main())\\n\"\n)\nwith open(f\"{assets_dir}/take_screenshot.py\", \"w\", encoding='utf-8') as f:\n f.write(screenshot_code)\n\nsubprocess.run([\"python3\", f\"{assets_dir}/take_screenshot.py\"], check=True)\n\ncmd = [\n \"ffmpeg\", \"-y\",\n \"-loop\", \"1\",\n \"-i\", screenshot_path,\n \"-i\", audio_path,\n \"-c:v\", \"libx264\",\n \"-tune\", \"stillimage\",\n \"-c:a\", \"aac\",\n \"-b:a\", \"192k\",\n \"-pix_fmt\", \"yuv420p\",\n \"-shortest\",\n video_path\n]\nsubprocess.run(cmd, check=True)\n\nif os.path.exists(video_path):\n size = os.path.getsize(video_path)\n print(f\"SUCCESS: https://bahi-bh-test-ckod.hf.space/files/{client_id}/cosmic_energy_presentation.mp4 (Size: {size} bytes)\")\nelse:\n print(\"ERROR: Video creation failed.\")\n", "languageId": "python"}}
|
|
|
|
| 648 |
## ⚙️ القواعد الأساسية العامة
|
| 649 |
- عند كتابة كود: اكتبه كاملاً وجاهزًا للتشغيل دون اختصار.
|
| 650 |
- استخدم الأدوات المتاحة كلما حسّنت النتيجة، ونفّذ الاستدعاءات المستقلة معًا عند الإمكان.
|