Update app.py
Browse files
app.py
CHANGED
|
@@ -24,13 +24,13 @@ import os import re import shutil import tempfile import traceback from pathlib
|
|
| 24 |
|
| 25 |
import pyzipper import gradio as gr from huggingface_hub import InferenceClient from docx import Document from PyPDF2 import PdfReader
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
ALLOWED_EXTENSIONS = {'.py', '.js', '.html', '.css', '.txt', '.json', '.md', '.php', '.yml', '.yaml', '.docx', '.pdf'} MAX_FILE_SIZE_BYTES = 200 * 1024
|
| 30 |
|
| 31 |
if not HF_TOKEN: print("تحذير: لم يتم ضبط HF_TOKEN. تأكد من تعيين HF_TOKEN لتشغيل نموذج Hugging Face.")
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
class Sandbox: def init(self): self.dir: Optional[str] = None self.files_content: Dict[str, str] = {} self.original_file_path: Optional[str] = None self.password: Optional[str] = None
|
| 36 |
|
|
@@ -110,9 +110,9 @@ def create_zip(self) -> Tuple[Optional[str], str]:
|
|
| 110 |
|
| 111 |
sandbox = Sandbox()
|
| 112 |
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
|
| 117 |
def api_reset(file, password):
|
| 118 |
if file is None:
|
|
@@ -128,7 +128,6 @@ def api_send_message(user_message, chat_history):
|
|
| 128 |
return chat_history
|
| 129 |
|
| 130 |
def api_apply_and_package(chat_history):
|
| 131 |
-
# لأغراض نموذجية
|
| 132 |
out_zip, msg = sandbox.create_zip()
|
| 133 |
return out_zip, msg
|
| 134 |
|
|
|
|
| 24 |
|
| 25 |
import pyzipper import gradio as gr from huggingface_hub import InferenceClient from docx import Document from PyPDF2 import PdfReader
|
| 26 |
|
| 27 |
+
إعدادات عامة
|
| 28 |
|
| 29 |
+
ALLOWED_EXTENSIONS = {'.py', '.js', '.html', '.css', '.txt', '.json', '.md', '.php', '.yml', '.yaml', '.docx', '.pdf'} MAX_FILE_SIZE_BYTES = 200 * 1024 MAX_TOTAL_FILES = 500 MAX_EXTRACTED_BYTES = 20 * 1024 * 1024 MODEL_ID = os.environ.get('HF_MODEL_ID', 'moonshotai/Kimi-K2-Instruct') HF_TOKEN = os.environ.get('HF_TOKEN')
|
| 30 |
|
| 31 |
if not HF_TOKEN: print("تحذير: لم يتم ضبط HF_TOKEN. تأكد من تعيين HF_TOKEN لتشغيل نموذج Hugging Face.")
|
| 32 |
|
| 33 |
+
صناديق الرمل
|
| 34 |
|
| 35 |
class Sandbox: def init(self): self.dir: Optional[str] = None self.files_content: Dict[str, str] = {} self.original_file_path: Optional[str] = None self.password: Optional[str] = None
|
| 36 |
|
|
|
|
| 110 |
|
| 111 |
sandbox = Sandbox()
|
| 112 |
|
| 113 |
+
واجهة Gradio
|
| 114 |
|
| 115 |
+
with gr.Blocks(title="Smart Dev Sandbox — المبرمج الذكي PRO") as demo: gr.Markdown("# 🚀 المبرمج الذكي PRO — Sandbox احترافي لتعديل مشاريع") with gr.Row(): with gr.Column(scale=3): chatbot = gr.Chatbot(label="محادثة المساعد") msg = gr.Textbox(placeholder="اطلب تعديلًا", label="طلب التعديل") send_btn = gr.Button("إرسال") with gr.Column(scale=1): file_input = gr.File(label="اختر ملف المشروع (ZIP / DOCX / PDF)") pwd_input = gr.Textbox(label="كلمة مرور (اختياري)", type="password") analyze = gr.Button("🔍 تحليل الملفات") status = gr.Markdown("الحالة: جاهز") gr.HTML("<hr>") save_btn = gr.Button("✨ تطبيق التعديلات وإنشاء ZIP") download_output = gr.File(label="حمل الملف المعدل")
|
| 116 |
|
| 117 |
def api_reset(file, password):
|
| 118 |
if file is None:
|
|
|
|
| 128 |
return chat_history
|
| 129 |
|
| 130 |
def api_apply_and_package(chat_history):
|
|
|
|
| 131 |
out_zip, msg = sandbox.create_zip()
|
| 132 |
return out_zip, msg
|
| 133 |
|