Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # 1. تحميل الموديل (Qwen 2.5 1.5B) | |
| # الموديل ده ممتاز لأنه صغير وسريع جداً على السيرفرات المجانية | |
| pipe = pipeline("text-generation", model="Qwen/Qwen2.5-1.5B-Instruct", device_map="auto") | |
| def generate_html(user_prompt): | |
| # 2. تجهيز الرسالة للموديل | |
| messages = [ | |
| {"role": "system", "content": "You are an expert HTML developer. Return only the code without explanations."}, | |
| {"role": "user", "content": f"Create a modern HTML/CSS code for: {user_prompt}"} | |
| ] | |
| # 3. عملية توليد الكود | |
| output = pipe(messages, max_new_tokens=512, return_full_text=False)[0]['generated_text'] | |
| return output | |
| # 4. بناء واجهة التطبيق بـ Gradio | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🚀 صانع الأكواد الذكي (Qwen 2.5)") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_text = gr.Textbox(label="صف الموقع اللي في خيالك", placeholder="مثلاً: صفحة هبوط لمطعم بيتزا بألوان جذابة...") | |
| btn = gr.Button("توليد الكود ✨", variant="primary") | |
| with gr.Column(): | |
| output_code = gr.Code(label="كود الـ HTML الجاهز", language="html") | |
| # ربط الزرار بالوظيفة | |
| btn.click(fn=generate_html, inputs=input_text, outputs=output_code) | |
| # تشغيل التطبيق | |
| demo.launch() |