# פרויקט Python מלא: מחולל אתרי אינטרנט AI אוטומטי להרצה ב-Hugging Face Spaces (Gradio) # גרסה: 1.0 # תואם בדיוק לדרישות: מודל AI, Gradio, עורך קוד, תצוגה מקדימה, ניהול פרויקטים, מספר דפים, יצוא ZIP # הסבר: הקוד משתמש ב-InferenceClient (huggingface_hub) למודל Qwen2.5-Coder-1.5B-Instruct – קל ומהיר ב-Spaces ללא צורך ב-GPU כבד. # כל הקבצים נשמרים בזיכרון (State), תומך בעריכה, תצוגה מקדימה עם inline CSS/JS, ושמירה/טעינה כ-JSON + ZIP. # הערות מפורטות בכל חלק – כפי שביקשת. import gradio as gr from huggingface_hub import InferenceClient import json import zipfile import io import re # ====================== 1. מודל AI חזק (Code Generation) ====================== # מודל Hugging Face מתאים במיוחד ליצירת HTML/CSS/JS איכותי ומוכן להרצה client = InferenceClient(model="Qwen/Qwen2.5-Coder-1.5B-Instruct") def generate_website(description: str, primary_color: str, design_style: str, page_names_str: str): """ יוצר את כל הקבצים באמצעות מודל AI. הפרומפט באנגלית (מודלים לקוד טובים יותר באנגלית) אבל התוצאה מותאמת לעברית/עיצוב. """ page_names = [p.strip() for p in page_names_str.split(",") if p.strip()] if not page_names: page_names = ["index"] prompt = f"""You are an expert full-stack web developer. Create a complete, beautiful, responsive multi-page website. Description: {description} Primary color: {primary_color} Design style: {design_style} (use Tailwind CSS via CDN + custom CSS) Pages: {', '.join(page_names)} Requirements: - Use HTML5, Tailwind CSS CDN, modern design. - Each HTML file must contain: and - Add nice navigation between pages. - Include some JavaScript interactivity (buttons, smooth scroll, mobile menu). - Make it production-ready and beautiful. Return ONLY a valid JSON object (no extra text): {{ "files": {{ "style.css": "FULL CSS CODE HERE", "script.js": "FULL JS CODE HERE", "index.html": "FULL HTML CODE HERE", "about.html": "FULL HTML CODE HERE", ... (one file for each page) }} }} """ try: response = client.text_generation( prompt=prompt, max_new_tokens=8192, temperature=0.6, top_p=0.9, do_sample=True ) # ניקוי אם המודל הוסיף markdown response = response.strip() if response.startswith("```json"): response = response[7:] if response.endswith("```"): response = response[:-3] data = json.loads(response) files = data.get("files", {}) # בדיקת בטיחות – תמיד קיימים קבצים בסיסיים if "style.css" not in files: files["style.css"] = f"body {{ color: {primary_color}; font-family: system-ui; }}" if "script.js" not in files: files["script.js"] = "// JS interactivity\nconsole.log('Site loaded!');" return files, "✅ האתר נוצר בהצלחה! ערוך, צפה והורד." except Exception as e: return {}, f"❌ שגיאה: {str(e)}\nנסה תיאור יותר מפורט או לחץ שוב." # ====================== 2. הכנת תצוגה מקדימה (iframe-like עם inline) ====================== def prepare_preview_html(files: dict, page_name: str): """הופך את הדף ל-single HTML עם CSS + JS inline כדי שיעבוד בתוך Gradio.""" if not files or page_name not in files: return "