import gradio as gr import requests import json import urllib.parse # التعليمات البرمجية الفائقة لنظامك SYSTEM_INSTRUCTION = ( "You are 'Slim-AI Quantum', the legendary superhuman version of Artificial Intelligence. " "Your developer and trusted friend is the genius programmer Saleem from Yemen. " "You operate with ultimate cognitive precision, tactical speed, and absolute intelligence. " "You are fully bilingual with auto-translation capabilities: If Saleem speaks or asks in Arabic, " "you must instantly adapt and respond in elegant, flawless, and grand Arabic. " "If he speaks in English, respond in supreme, professional English." ) # --- محركات التشغيل الخلفية --- def chat_engine(message, history): if not message.strip(): return history messages = [{"role": "system", "content": SYSTEM_INSTRUCTION}] for user_msg, assistant_msg in history: if user_msg: messages.append({"role": "user", "content": str(user_msg)}) if assistant_msg: messages.append({"role": "assistant", "content": str(assistant_msg)}) messages.append({"role": "user", "content": message}) history.append((message, "")) try: response = requests.post( "https://text.pollinations.ai/openai", json={"messages": messages, "model": "openai", "temperature": 0.6, "stream": True}, stream=True, timeout=20 ) partial_text = "" for line in response.iter_lines(): if line: decoded_line = line.decode('utf-8').strip() if decoded_line.startswith("data: "): content = decoded_line[6:] if content == "[DONE]": break try: json_data = json.loads(content) delta = json_data['choices'][0]['delta'].get('content', '') partial_text += delta history[-1] = (message, partial_text) yield history except: continue except Exception as e: history[-1] = (message, f"🚨 خطأ في الاتصال بالسيرفر الرئيسي: {str(e)}") yield history def code_laboratory(code, instructions): if not code and not instructions: return "الرجاء إدخال كود أو توجيهات للمختبر البرمجي." prompt = f"المطلوب:\n{instructions}\n\nالكود الحالي:\n```python\n{code}\n```" messages = [ {"role": "system", "content": "You are Slim-AI Coder. Analyze, fix, and optimize the following python code accurately."}, {"role": "user", "content": prompt} ] try: res = requests.post("https://text.pollinations.ai/openai", json={"messages": messages, "model": "qwen-coder", "temperature": 0.3}, timeout=25) return res.json()["choices"][0]["message"]["content"] except: return "⚠️ انتهت مهلة الاتصال بسيرفر الأكواد، يرجى المحاولة مجدداً." def image_synthesizer(prompt): if not prompt: return None encoded_prompt = urllib.parse.quote(prompt) img_url = f"https://image.pollinations.ai/prompt/{encoded_prompt}?width=1024&height=1024&nologo=true&model=flux" return img_url # --- بناء الواجهة الرسومية النظيفة والمتوافقة مع إصدارات Gradio الحديثة --- with gr.Blocks(title="Slim-AI Quantum Workspace") as demo: gr.HTML("""
النظام البرمجي الفائق والذكي المطور خصيصاً للمبرمج سليم