File size: 2,230 Bytes
d1b249e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""
اختبار سريع للتأكد من أن التطبيق يعمل قبل النشر
"""

import sys
import os

def test_imports():
    """اختبار الاستيراد"""
    try:
        import torch
        import gradio as gr
        import spaces
        from transformers import AutoTokenizer, AutoModelForCausalLM
        print("✅ جميع الاستيرادات نجحت")
        return True
    except ImportError as e:
        print(f"❌ خطأ في الاستيراد: {e}")
        return False

def test_model_loading():
    """اختبار تحميل المودل"""
    try:
        from transformers import AutoTokenizer, AutoModelForCausalLM
        import torch

        model_path = "anaspro/iraqi-7b"
        hf_token = os.getenv("HF_TOKEN")

        print("🔄 جاري تحميل المودل للاختبار...")

        # تحميل سريع للاختبار فقط
        tokenizer = AutoTokenizer.from_pretrained(
            model_path,
            token=hf_token,
            trust_remote_code=True
        )

        # تحميل المودل على CPU فقط للاختبار
        model = AutoModelForCausalLM.from_pretrained(
            model_path,
            device_map="cpu",  # استخدام CPU للاختبار فقط
            trust_remote_code=True,
            token=hf_token,
            torch_dtype=torch.float32,
            low_cpu_mem_usage=True
        )

        print("✅ تحميل المودل نجح")
        return True

    except Exception as e:
        print(f"❌ خطأ في تحميل المودل: {e}")
        return False

def main():
    print("🚀 اختبار النشر على Hugging Face ZeroGPU")
    print("=" * 50)

    # اختبار الاستيراد
    if not test_imports():
        sys.exit(1)

    # اختبار تحميل المودل
    if not test_model_loading():
        sys.exit(1)

    print("\n🎉 جميع الاختبارات نجحت! التطبيق جاهز للنشر")
    print("\n📋 الملفات المطلوبة للنشر:")
    print("- app.py")
    print("- requirements.txt")
    print("- README.md")
    print("- system_prompt.txt")

if __name__ == "__main__":
    main()