File size: 1,869 Bytes
8deec51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
import subprocess

# 📌 Hugging Face Token (Hacı)
HF_TOKEN = "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"  # Senin tokenin

# 📌 Gerekli modülleri kontrol et ve yükle
required_modules = ["torch", "transformers"]
for module in required_modules:
    try:
        __import__(module)
        print(f"✅ {module} zaten yüklü.")
    except ImportError:
        print(f"⚠️ {module} eksik! Kuruluyor... 🛠️")
        subprocess.run(["pip", "install", module], check=True)
        print(f"✅ {module} başarıyla kuruldu!")

# 📌 GPU Kontrolü
device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"✅ Kullanılan Cihaz: {device}")

# 📌 Qwen Modeli Yükleme
MODEL_NAME = "Qwen/Qwen2.5-Math-1.5B"

try:
    print(f"📌 {MODEL_NAME} modeli indiriliyor ve yükleniyor...")
    
    # 🔥 trust_remote_code=True EKLEDİK! 🔥
    tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, token=HF_TOKEN, trust_remote_code=True)
    
    model = AutoModelForCausalLM.from_pretrained(
        MODEL_NAME,
        token=HF_TOKEN,
        trust_remote_code=True,  # 🔥 Bu kritik! 🔥
        torch_dtype=torch.float16,
        device_map="auto"
    )

    print("✅ Model başarıyla yüklendi!")
except Exception as e:
    print(f"⚠️ Model yükleme başarısız! Hata: {e}")
    print("📌 Çözüm: Hugging Face tokenini ve model erişimini kontrol et.")

# 📌 Model Etkileşimi
while True:
    user_input = input("👤 Sen: ")
    if user_input.lower() in ["exit", "çıkış"]:
        print("🔄 Kapatılıyor...")
        break

    inputs = tokenizer(user_input, return_tensors="pt").to(device)
    outputs = model.generate(**inputs, max_length=100)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    print(f"🤖 Bot: {response}")