|
|
"""
|
|
|
🚀 Nova AI - Basit Konsol Uygulaması
|
|
|
Teknova tarafından geliştirilen özgün yapay zeka modeli
|
|
|
Hub ve local model desteği
|
|
|
"""
|
|
|
|
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
import torch
|
|
|
import os
|
|
|
|
|
|
|
|
|
MODELS = {
|
|
|
"1": {"name": "Nova AI Hub", "path": "veteroner/NovaAI"},
|
|
|
"2": {"name": "Local Model", "path": "./nova-ai-model"}
|
|
|
}
|
|
|
|
|
|
def select_model():
|
|
|
"""Kullanıcıdan model seçimi al"""
|
|
|
print("\n📋 Model Seçimi:")
|
|
|
for key, value in MODELS.items():
|
|
|
if value["path"].startswith("./"):
|
|
|
status = "✅" if os.path.exists(value["path"]) else "❌"
|
|
|
else:
|
|
|
status = "🌐"
|
|
|
print(f"{key}. {value['name']} {status}")
|
|
|
|
|
|
while True:
|
|
|
choice = input("\nModel seçin (1 veya 2): ").strip()
|
|
|
if choice in MODELS:
|
|
|
return MODELS[choice]["path"], MODELS[choice]["name"]
|
|
|
print("❌ Geçersiz seçim! 1 veya 2 yazın.")
|
|
|
|
|
|
def load_model(model_path, model_name):
|
|
|
"""Seçilen modeli yükle"""
|
|
|
print(f"\n🚀 {model_name} yükleniyor...")
|
|
|
|
|
|
|
|
|
if model_path.startswith("./") and not os.path.exists(model_path):
|
|
|
print(f"❌ Local model bulunamadı: {model_path}")
|
|
|
return None, None
|
|
|
|
|
|
try:
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
model_path,
|
|
|
trust_remote_code=True
|
|
|
)
|
|
|
|
|
|
|
|
|
load_kwargs = {
|
|
|
"torch_dtype": torch.float16,
|
|
|
"trust_remote_code": True
|
|
|
}
|
|
|
|
|
|
|
|
|
if torch.cuda.is_available():
|
|
|
print("🎮 GPU tespit edildi, GPU kullanılacak")
|
|
|
load_kwargs["device_map"] = "auto"
|
|
|
else:
|
|
|
print("💻 CPU kullanılacak")
|
|
|
load_kwargs["device_map"] = None
|
|
|
|
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained(
|
|
|
model_path,
|
|
|
**load_kwargs
|
|
|
)
|
|
|
|
|
|
print(f"✅ {model_name} başarıyla yüklendi!")
|
|
|
return model, tokenizer
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f"❌ Model yükleme hatası: {e}")
|
|
|
return None, None
|
|
|
|
|
|
def chat_with_nova(message, model, tokenizer, max_tokens=256):
|
|
|
"""Nova AI ile sohbet et"""
|
|
|
try:
|
|
|
|
|
|
conversation = f"Kullanıcı: {message}\nNova AI:"
|
|
|
|
|
|
|
|
|
inputs = tokenizer(
|
|
|
conversation,
|
|
|
return_tensors="pt",
|
|
|
truncation=True,
|
|
|
max_length=1024
|
|
|
)
|
|
|
|
|
|
|
|
|
if model.device.type != 'cpu':
|
|
|
inputs = inputs.to(model.device)
|
|
|
|
|
|
|
|
|
with torch.no_grad():
|
|
|
outputs = model.generate(
|
|
|
**inputs,
|
|
|
max_new_tokens=max_tokens,
|
|
|
temperature=0.7,
|
|
|
top_p=0.9,
|
|
|
do_sample=True,
|
|
|
pad_token_id=tokenizer.eos_token_id,
|
|
|
eos_token_id=tokenizer.eos_token_id
|
|
|
)
|
|
|
|
|
|
|
|
|
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
nova_response = response[len(conversation):].strip()
|
|
|
|
|
|
return nova_response if nova_response else "Üzgünüm, yanıt üretemedi."
|
|
|
|
|
|
except Exception as e:
|
|
|
return f"❌ Hata: {e}"
|
|
|
|
|
|
def main():
|
|
|
"""Ana uygulama"""
|
|
|
print("=" * 50)
|
|
|
print("🚀 NOVA AI - BASİT KONSOL UYGULAMASI")
|
|
|
print("🌟 Teknova Özgün Yapay Zeka Modeli")
|
|
|
print("=" * 50)
|
|
|
|
|
|
|
|
|
model_path, model_name = select_model()
|
|
|
|
|
|
|
|
|
model, tokenizer = load_model(model_path, model_name)
|
|
|
|
|
|
if model is None or tokenizer is None:
|
|
|
print("❌ Program sonlandırılıyor.")
|
|
|
return
|
|
|
|
|
|
print(f"\n🎉 {model_name} ile sohbet hazır!")
|
|
|
print("💬 Komutlar:")
|
|
|
print(" - Mesaj yazarak sohbet edin")
|
|
|
print(" - 'exit' yazarak çıkın")
|
|
|
print(" - 'model' yazarak model değiştirin")
|
|
|
print("-" * 50)
|
|
|
|
|
|
while True:
|
|
|
try:
|
|
|
user_input = input("\n👤 Siz: ").strip()
|
|
|
|
|
|
|
|
|
if user_input.lower() in ['exit', 'çıkış', 'quit', 'q']:
|
|
|
print("\n🚀 Nova AI - Görüşmek üzere!")
|
|
|
break
|
|
|
|
|
|
|
|
|
if user_input.lower() == 'model':
|
|
|
print("\n🔄 Model değiştiriliyor...")
|
|
|
model_path, model_name = select_model()
|
|
|
model, tokenizer = load_model(model_path, model_name)
|
|
|
if model is None:
|
|
|
continue
|
|
|
print(f"✅ {model_name} aktif!")
|
|
|
continue
|
|
|
|
|
|
|
|
|
if not user_input:
|
|
|
print("🤖 Nova AI: Lütfen bir mesaj yazın.")
|
|
|
continue
|
|
|
|
|
|
|
|
|
print("🤖 Nova AI düşünüyor...")
|
|
|
response = chat_with_nova(user_input, model, tokenizer)
|
|
|
print(f"🤖 Nova AI: {response}")
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
print("\n\n🚀 Nova AI - Program sonlandırıldı!")
|
|
|
break
|
|
|
except Exception as e:
|
|
|
print(f"❌ Beklenmeyen hata: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main() |