|
|
"""
|
|
|
🚀 Nova AI - Hugging Face Spaces ZeroGPU
|
|
|
Teknova tarafından geliştirilen özgün yapay zeka modeli
|
|
|
ZeroGPU ile hızlandırılmış
|
|
|
"""
|
|
|
|
|
|
import gradio as gr
|
|
|
import torch
|
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
import os
|
|
|
|
|
|
|
|
|
try:
|
|
|
import spaces
|
|
|
HAS_SPACES = True
|
|
|
except ImportError:
|
|
|
HAS_SPACES = False
|
|
|
|
|
|
def spaces_gpu(func):
|
|
|
return func
|
|
|
spaces = type('spaces', (), {'GPU': spaces_gpu})()
|
|
|
|
|
|
|
|
|
MODEL_PATH = "nova-ai-model"
|
|
|
|
|
|
|
|
|
model = None
|
|
|
tokenizer = None
|
|
|
|
|
|
@spaces.GPU
|
|
|
def load_model():
|
|
|
"""Nova AI modelini ZeroGPU ile yükle"""
|
|
|
global model, tokenizer
|
|
|
|
|
|
print("🚀 Nova AI modeli ZeroGPU ile yükleniyor...")
|
|
|
|
|
|
try:
|
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
MODEL_PATH,
|
|
|
trust_remote_code=True,
|
|
|
use_fast=True
|
|
|
)
|
|
|
|
|
|
|
|
|
if tokenizer.pad_token is None:
|
|
|
tokenizer.pad_token = tokenizer.eos_token
|
|
|
|
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained(
|
|
|
MODEL_PATH,
|
|
|
torch_dtype=torch.float16,
|
|
|
device_map="auto",
|
|
|
trust_remote_code=True,
|
|
|
low_cpu_mem_usage=True
|
|
|
)
|
|
|
|
|
|
print("✅ Nova AI modeli ZeroGPU ile yüklendi!")
|
|
|
return "✅ Nova AI hazır! (ZeroGPU)"
|
|
|
|
|
|
except Exception as e:
|
|
|
error_msg = f"❌ Model yükleme hatası: {str(e)}"
|
|
|
print(error_msg)
|
|
|
return error_msg
|
|
|
|
|
|
@spaces.GPU
|
|
|
def chat_with_nova(message, history):
|
|
|
"""Nova AI ile sohbet et - ZeroGPU destekli"""
|
|
|
global model, tokenizer
|
|
|
|
|
|
if model is None or tokenizer is None:
|
|
|
|
|
|
load_status = load_model()
|
|
|
if "❌" in load_status:
|
|
|
return load_status
|
|
|
|
|
|
if not message.strip():
|
|
|
return "❓ Lütfen bir mesaj yazın."
|
|
|
|
|
|
try:
|
|
|
|
|
|
conversation = ""
|
|
|
for user_msg, bot_msg in history:
|
|
|
if user_msg and bot_msg:
|
|
|
conversation += f"Kullanıcı: {user_msg}\nNova AI: {bot_msg}\n"
|
|
|
|
|
|
|
|
|
conversation += f"Kullanıcı: {message}\nNova AI:"
|
|
|
|
|
|
|
|
|
inputs = tokenizer(
|
|
|
conversation,
|
|
|
return_tensors="pt",
|
|
|
truncation=True,
|
|
|
max_length=1024,
|
|
|
padding=True
|
|
|
)
|
|
|
|
|
|
|
|
|
if torch.cuda.is_available():
|
|
|
inputs = {k: v.to(model.device) for k, v in inputs.items()}
|
|
|
|
|
|
|
|
|
with torch.no_grad():
|
|
|
outputs = model.generate(
|
|
|
**inputs,
|
|
|
max_new_tokens=256,
|
|
|
temperature=0.7,
|
|
|
top_p=0.9,
|
|
|
do_sample=True,
|
|
|
pad_token_id=tokenizer.pad_token_id,
|
|
|
eos_token_id=tokenizer.eos_token_id,
|
|
|
repetition_penalty=1.1
|
|
|
)
|
|
|
|
|
|
|
|
|
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: {str(e)}"
|
|
|
|
|
|
|
|
|
with gr.Blocks(
|
|
|
theme=gr.themes.Soft(),
|
|
|
title="Nova AI - ZeroGPU",
|
|
|
css="""
|
|
|
.gradio-container {
|
|
|
max-width: 800px;
|
|
|
margin: 0 auto;
|
|
|
}
|
|
|
.chat-message {
|
|
|
padding: 10px;
|
|
|
margin: 5px 0;
|
|
|
border-radius: 10px;
|
|
|
}
|
|
|
"""
|
|
|
) as demo:
|
|
|
|
|
|
gr.HTML("""
|
|
|
<div style="text-align: center; padding: 20px;">
|
|
|
<h1 style="background: linear-gradient(135deg, #ff6b6b, #4ecdc4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-size: 2.5rem; font-weight: bold;">
|
|
|
🚀 Teknova Nova AI
|
|
|
</h1>
|
|
|
<p style="font-size: 1.2rem; color: #666; margin: 10px 0;">
|
|
|
<strong>Teknova</strong> tarafından geliştirilen <strong>özgün</strong> yapay zeka modeli
|
|
|
</p>
|
|
|
<div style="background: linear-gradient(135deg, #ff6b6b, #4ecdc4); color: white; padding: 8px 16px; border-radius: 20px; display: inline-block; font-size: 0.9rem;">
|
|
|
⚡ Özgün Nova AI • 🧠 Teknova Innovation • 🚀 ZeroGPU Hızlı
|
|
|
</div>
|
|
|
<p style="font-size: 0.9rem; color: #888; margin-top: 10px;">
|
|
|
🌟 Hugging Face ZeroGPU ile hızlandırılmış
|
|
|
</p>
|
|
|
</div>
|
|
|
""")
|
|
|
|
|
|
chatbot = gr.ChatInterface(
|
|
|
fn=chat_with_nova,
|
|
|
title="Nova AI Chat",
|
|
|
description="Teknova'nın özgün yapay zeka modeli ile sohbet edin",
|
|
|
examples=[
|
|
|
"Merhaba Nova AI, nasılsın?",
|
|
|
"Yapay zeka nedir?",
|
|
|
"Teknova hakkında bilgi ver",
|
|
|
"Bana bir hikaye anlat",
|
|
|
"Python programlama hakkında bilgi ver"
|
|
|
],
|
|
|
cache_examples=False,
|
|
|
retry_btn="🔄 Tekrar Dene",
|
|
|
undo_btn="↩️ Geri Al",
|
|
|
clear_btn="🗑️ Temizle",
|
|
|
submit_btn="🚀 Gönder",
|
|
|
textbox=gr.Textbox(
|
|
|
placeholder="Nova AI ile sohbet etmek için mesajınızı yazın...",
|
|
|
container=False,
|
|
|
scale=7
|
|
|
)
|
|
|
)
|
|
|
|
|
|
gr.HTML("""
|
|
|
<div style="text-align: center; padding: 15px; color: #666; font-size: 0.9rem;">
|
|
|
<p>🌟 <strong>Teknova Nova AI</strong> - Tamamen özgün Türkçe dil modeli</p>
|
|
|
<p>🚀 ZeroGPU teknolojisi ile hızlandırılmış</p>
|
|
|
<p style="color: #999;">⚡ Teknova Innovation ile güçlendirilmiştir</p>
|
|
|
</div>
|
|
|
""")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
demo.launch(
|
|
|
server_name="0.0.0.0",
|
|
|
server_port=7860,
|
|
|
share=False
|
|
|
) |