File size: 1,544 Bytes
faf6ef1
010e455
faf6ef1
010e455
 
 
faf6ef1
010e455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faf6ef1
1f7e485
010e455
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()