import gradio as gr from transformers import pipeline import torch # 1. إعداد الموديل model_id = "hhuihiu/ADAM-STUDIO-MAX" device = 0 if torch.cuda.is_available() else -1 pipe = pipeline( "text-generation", model=model_id, device=device, model_kwargs={"dtype": torch.float16 if torch.cuda.is_available() else torch.float32} ) def chat_adam(message, history): system_prompt = "You are ADAM-STUDIO-MAX, a professional AI coder created by Adam Mahmoud Abdelalim. Use code blocks for all code answers." # بناء الـ Prompt full_prompt = f"{system_prompt}\n" # التعامل مع history كنظام Tuples (للنسخ القديمة) if history is None: history = [] for user_msg, bot_msg in history: full_prompt += f"User: {user_msg}\nAI: {bot_msg}\n" full_prompt += f"User: {message}\nAI:" # توليد الرد result = pipe( full_prompt, max_new_tokens=1024, do_sample=True, temperature=0.7, return_full_text=False )[0]['generated_text'] response = result.strip() # إضافة الرسالة الجديدة للـ history history.append((message, response)) return "", history # بناء الواجهة with gr.Blocks() as demo: with gr.Row(): with gr.Column(scale=8): gr.Markdown(""" # 🤖 ADAM-STUDIO-TERMINAL v1.1 ### Developed by: **Adam Mahmoud Abdelalim** 🇪🇬 """) with gr.Column(scale=2): site_btn = gr.Button("🌐 Visit ADAM STUDIO", variant="primary") site_btn.click(None, None, None, js="window.open('https://adam-studio-platform.wasmer.app/', '_blank')") with gr.Tabs(): with gr.TabItem("💬 AI Chat Terminal"): # شيلنا type="messages" عشان النسخ القديمة chatbot = gr.Chatbot( label="Adam Studio Code Assistant", height=600 ) msg = gr.Textbox( label="Type your code or question...", placeholder="e.g., How to build a web api in .NET?", show_label=False ) with gr.Row(): submit = gr.Button("Run Script 🚀", variant="primary") clear = gr.ClearButton([msg, chatbot], value="Clear Terminal") submit.click(chat_adam, [msg, chatbot], [msg, chatbot]) msg.submit(chat_adam, [msg, chatbot], [msg, chatbot]) # التشغيل demo.launch( theme=gr.themes.Monochrome(), css=".gradio-container {background-color: #0b0f19;}" )