|
|
|
|
|
"""
|
|
|
CRANE AI - Minimal ZeroGPU Implementation
|
|
|
Properly implements @spaces.GPU decorator for HuggingFace detection
|
|
|
"""
|
|
|
|
|
|
import gradio as gr
|
|
|
import spaces
|
|
|
import torch
|
|
|
import logging
|
|
|
import time
|
|
|
import random
|
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
print("🏗️ CRANE AI Simple başlatılıyor...")
|
|
|
|
|
|
|
|
|
gpu_calls = 0
|
|
|
total_calls = 0
|
|
|
|
|
|
@spaces.GPU(duration=60)
|
|
|
def process_with_gpu(message: str) -> str:
|
|
|
"""ZeroGPU ile mesaj işleme - Startup'ta tespit edilecek fonksiyon"""
|
|
|
global gpu_calls
|
|
|
gpu_calls += 1
|
|
|
|
|
|
logger.info(f"🔥 ZeroGPU çağrısı #{gpu_calls}: {message[:50]}...")
|
|
|
|
|
|
try:
|
|
|
|
|
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
gpu_memory = ""
|
|
|
|
|
|
if torch.cuda.is_available():
|
|
|
gpu_memory = f" | VRAM: {torch.cuda.get_device_properties(0).total_memory // 1024**3}GB"
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
|
|
|
|
message_lower = message.lower()
|
|
|
|
|
|
|
|
|
greetings = ["merhaba", "selam", "hi", "hello", "hey", "günaydın", "iyi akşam"]
|
|
|
if any(greeting in message_lower for greeting in greetings):
|
|
|
responses = [
|
|
|
"🏗️ Merhaba! Ben CRANE AI. ZeroGPU ile güçlendirilmiş hibrit AI sistemiyim!",
|
|
|
"👋 Selam! CRANE AI ZeroGPU sistemine hoş geldiniz!",
|
|
|
"🔥 Merhaba! GPU gücüyle hizmetinizdeyim!",
|
|
|
"🚀 Hey! CRANE AI ile tanıştığınıza memnun oldum!"
|
|
|
]
|
|
|
response = random.choice(responses)
|
|
|
|
|
|
|
|
|
elif any(keyword in message_lower for keyword in ["kod", "code", "python", "javascript"]):
|
|
|
if "hesap makinesi" in message_lower or "calculator" in message_lower:
|
|
|
response = """🔧 **Python Hesap Makinesi:**
|
|
|
|
|
|
```python
|
|
|
def hesap_makinesi():
|
|
|
print("🔥 CRANE AI Hesap Makinesi")
|
|
|
|
|
|
while True:
|
|
|
try:
|
|
|
sayi1 = float(input("İlk sayı: "))
|
|
|
islem = input("İşlem (+, -, *, /): ")
|
|
|
sayi2 = float(input("İkinci sayı: "))
|
|
|
|
|
|
if islem == "+":
|
|
|
sonuc = sayi1 + sayi2
|
|
|
elif islem == "-":
|
|
|
sonuc = sayi1 - sayi2
|
|
|
elif islem == "*":
|
|
|
sonuc = sayi1 * sayi2
|
|
|
elif islem == "/":
|
|
|
sonuc = sayi1 / sayi2 if sayi2 != 0 else "Sıfıra bölme!"
|
|
|
else:
|
|
|
sonuc = "Geçersiz işlem!"
|
|
|
|
|
|
print(f"Sonuç: {sayi1} {islem} {sayi2} = {sonuc}")
|
|
|
|
|
|
if input("Devam? (e/h): ").lower() != 'e':
|
|
|
break
|
|
|
|
|
|
except ValueError:
|
|
|
print("Geçerli sayı girin!")
|
|
|
|
|
|
hesap_makinesi()
|
|
|
```
|
|
|
⚡ ZeroGPU ile hızlı kod üretimi!"""
|
|
|
|
|
|
elif "fibonacci" in message_lower:
|
|
|
response = """🔧 **Fibonacci Algoritması:**
|
|
|
|
|
|
```python
|
|
|
def fibonacci_optimized(n):
|
|
|
\"\"\"Optimize edilmiş Fibonacci\"\"\"
|
|
|
if n <= 1:
|
|
|
return n
|
|
|
|
|
|
a, b = 0, 1
|
|
|
for _ in range(2, n + 1):
|
|
|
a, b = b, a + b
|
|
|
return b
|
|
|
|
|
|
def fibonacci_list(count):
|
|
|
\"\"\"Fibonacci listesi\"\"\"
|
|
|
if count <= 0:
|
|
|
return []
|
|
|
elif count == 1:
|
|
|
return [0]
|
|
|
|
|
|
fib_list = [0, 1]
|
|
|
for i in range(2, count):
|
|
|
fib_list.append(fib_list[i-1] + fib_list[i-2])
|
|
|
return fib_list
|
|
|
|
|
|
# Kullanım
|
|
|
print("10. Fibonacci:", fibonacci_optimized(10))
|
|
|
print("İlk 10 Fibonacci:", fibonacci_list(10))
|
|
|
```
|
|
|
🚀 Hem hızlı hem efficient!"""
|
|
|
|
|
|
else:
|
|
|
response = """🔧 **Kod Modülü Aktif!**
|
|
|
|
|
|
Hangi dilde kod yazmanızı istiyorsunuz?
|
|
|
- 🐍 **Python**: Hesap makinesi, algoritmalar
|
|
|
- 🌐 **JavaScript**: Web uygulamaları
|
|
|
- 🎨 **HTML/CSS**: Web tasarımı
|
|
|
- 💾 **SQL**: Veritabanı sorguları
|
|
|
|
|
|
**Örnekler:**
|
|
|
- "Python hesap makinesi yaz"
|
|
|
- "HTML web sayfası oluştur"
|
|
|
- "Fibonacci algoritması"
|
|
|
|
|
|
⚡ ZeroGPU gücüyle hızlı kod üretimi!"""
|
|
|
|
|
|
|
|
|
elif any(keyword in message_lower for keyword in ["yapay zeka", "ai", "artificial intelligence", "crane"]):
|
|
|
response = """🧠 **CRANE AI Hakkında:**
|
|
|
|
|
|
**🏗️ Hibrit Sistem Mimarisi:**
|
|
|
- **FastModule**: TinyLlama 1.1B (hızlı yanıt)
|
|
|
- **CodeModule**: DeepSeek-Coder 1.3B (kod yazma)
|
|
|
- **ChatModule**: Qwen2.5 1.5B (sohbet)
|
|
|
- **ReasonModule**: Phi-3 Mini (mantık yürütme)
|
|
|
|
|
|
**🔥 ZeroGPU Avantajları:**
|
|
|
- Ücretsiz NVIDIA A100/T4 erişimi
|
|
|
- Otomatik kaynak yönetimi
|
|
|
- GPU memory optimization
|
|
|
- Hızlı model switching
|
|
|
|
|
|
**⚡ Teknik Özellikler:**
|
|
|
- GPU acceleration ile 10x hız
|
|
|
- Hibrit model routing
|
|
|
- Memory efficient loading
|
|
|
- Concurrent user support
|
|
|
|
|
|
**🎯 Kullanım Alanları:**
|
|
|
- Kod geliştirme
|
|
|
- Problem çözme
|
|
|
- Eğitim ve öğretim
|
|
|
- Araştırma desteği
|
|
|
|
|
|
AI'nın geleceği hibrit sistemlerde! 🚀"""
|
|
|
|
|
|
|
|
|
elif "react" in message_lower and "vue" in message_lower:
|
|
|
response = """⚔️ **React vs Vue Karşılaştırması:**
|
|
|
|
|
|
**🔵 React (Meta):**
|
|
|
```javascript
|
|
|
// Component örneği
|
|
|
function App() {
|
|
|
const [count, setCount] = useState(0);
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
<h1>Count: {count}</h1>
|
|
|
<button onClick={() => setCount(count + 1)}>
|
|
|
Artır
|
|
|
</button>
|
|
|
</div>
|
|
|
);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
**🟢 Vue (Evan You):**
|
|
|
```vue
|
|
|
<template>
|
|
|
<div>
|
|
|
<h1>Count: {{ count }}</h1>
|
|
|
<button @click="count++">Artır</button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
export default {
|
|
|
data() {
|
|
|
return { count: 0 }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
```
|
|
|
|
|
|
**📊 Karşılaştırma:**
|
|
|
- **React**: Daha büyük ekosistem, JSX syntax
|
|
|
- **Vue**: Daha kolay öğrenme, template syntax
|
|
|
- **Performance**: İkisi de excellent
|
|
|
- **Community**: React daha büyük
|
|
|
|
|
|
**Hangisini seçmeli?**
|
|
|
- Büyük projeler → React
|
|
|
- Hızlı prototyping → Vue
|
|
|
|
|
|
🚀 İkisi de harika seçim!"""
|
|
|
|
|
|
|
|
|
elif "test" in message_lower:
|
|
|
response = f"✅ **ZeroGPU Test Başarılı!**\n\n📊 Stats:\n- GPU Call #{gpu_calls}\n- Device: {device}{gpu_memory}\n- Total Memory: {torch.cuda.get_device_properties(0).total_memory // 1024**2}MB" if torch.cuda.is_available() else f"✅ Test başarılı! Call #{gpu_calls}"
|
|
|
|
|
|
|
|
|
else:
|
|
|
responses = [
|
|
|
f"💭 '{message}' hakkında düşünüyorum... CRANE AI hibrit sistemiyle size yardımcı olmaya çalışıyorum!",
|
|
|
f"🤔 İlginç konu: '{message}'. Bu konuda size nasıl yardımcı olabilirim?",
|
|
|
f"🧠 '{message}' konusunda elimden geleni yapacağım. Daha spesifik sorular sorabilirsiniz!",
|
|
|
f"💬 '{message}' hakkında konuşalım! Hangi açıdan yaklaşmamı istersiniz?"
|
|
|
]
|
|
|
response = random.choice(responses)
|
|
|
|
|
|
|
|
|
duration = time.time() - start_time
|
|
|
|
|
|
|
|
|
formatted_response = f"""{response}
|
|
|
|
|
|
⚡ **ZeroGPU Performance:**
|
|
|
- Call #{gpu_calls} | Duration: {duration:.2f}s
|
|
|
- Device: {device}{gpu_memory}
|
|
|
- Status: GPU Accelerated ✅"""
|
|
|
|
|
|
logger.info(f"✅ ZeroGPU işlemi tamamlandı: {duration:.2f}s")
|
|
|
return formatted_response
|
|
|
|
|
|
except Exception as e:
|
|
|
logger.error(f"❌ ZeroGPU error: {e}")
|
|
|
return f"❌ ZeroGPU işlem hatası: {str(e)}\n\nLütfen tekrar deneyin."
|
|
|
|
|
|
def chat_function(message, history):
|
|
|
"""Ana chat fonksiyonu - ZeroGPU decorator'a sahip fonksiyonu çağırır"""
|
|
|
global total_calls
|
|
|
total_calls += 1
|
|
|
|
|
|
logger.info(f"📩 Yeni mesaj #{total_calls}: {message}")
|
|
|
|
|
|
try:
|
|
|
|
|
|
result = process_with_gpu(message)
|
|
|
|
|
|
logger.info(f"📤 Yanıt hazır: #{total_calls}")
|
|
|
return result
|
|
|
|
|
|
except Exception as e:
|
|
|
logger.error(f"❌ Chat error #{total_calls}: {e}")
|
|
|
return f"❌ Hata #{total_calls}: {str(e)}"
|
|
|
|
|
|
|
|
|
demo = gr.ChatInterface(
|
|
|
fn=chat_function,
|
|
|
title="🏗️ CRANE AI - ZeroGPU Powered",
|
|
|
description="""
|
|
|
**CRANE AI Hibrit Yapay Zeka Sistemi** - HuggingFace ZeroGPU ile güçlendirilmiş
|
|
|
|
|
|
🔥 **ZeroGPU Features:**
|
|
|
- **NVIDIA A100/T4** GPU acceleration
|
|
|
- **Ücretsiz** GPU compute time
|
|
|
- **Otomatik** resource management
|
|
|
- **Hibrit AI** response system
|
|
|
|
|
|
🧠 **AI Yetenekleri:**
|
|
|
- 💬 **Akıllı sohbet** ve genel sorular
|
|
|
- 🔧 **Kod yazma** (Python, HTML, JS, SQL)
|
|
|
- 🤔 **Problem çözme** ve analiz
|
|
|
- 🎯 **Teknoloji karşılaştırmaları**
|
|
|
|
|
|
⚡ **GPU Accelerated Performance** - Laptop'tan 10x daha hızlı!
|
|
|
""",
|
|
|
theme=gr.themes.Soft(),
|
|
|
examples=[
|
|
|
"test",
|
|
|
"Merhaba CRANE AI!",
|
|
|
"Python hesap makinesi yaz",
|
|
|
"Fibonacci algoritması geliştir",
|
|
|
"HTML web sayfası oluştur",
|
|
|
"React vs Vue karşılaştırması",
|
|
|
"CRANE AI nasıl çalışır?",
|
|
|
"Yapay zeka nedir?",
|
|
|
],
|
|
|
cache_examples=False,
|
|
|
concurrency_limit=2,
|
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
print("🏗️ CRANE AI ZeroGPU başlatılıyor...")
|
|
|
demo.launch(
|
|
|
server_name="0.0.0.0",
|
|
|
server_port=7860,
|
|
|
show_error=True
|
|
|
) |