File size: 9,715 Bytes
58c4fec 805fa80 01ccedb 805fa80 01ccedb 805fa80 f585a55 805fa80 58c4fec f585a55 805fa80 01ccedb 4a9efcd 01ccedb 4a9efcd 01ccedb 319159f f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb 4a9efcd 01ccedb 4a9efcd f585a55 01ccedb f585a55 4a9efcd f585a55 4a9efcd 77aee1b 01ccedb 77aee1b 01ccedb 4a9efcd 77aee1b 01ccedb f585a55 01ccedb f585a55 01ccedb 77aee1b 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb 319159f 01ccedb 77aee1b 01ccedb 77aee1b 01ccedb f585a55 01ccedb 319159f 01ccedb 319159f 01ccedb 77aee1b 01ccedb 77aee1b 01ccedb 77aee1b f585a55 01ccedb f585a55 01ccedb f585a55 01ccedb 805fa80 01ccedb 58c4fec f585a55 01ccedb 58c4fec 01ccedb 7cb74e8 01ccedb 7cb74e8 01ccedb 7cb74e8 01ccedb 58c4fec f585a55 58c4fec 319159f f585a55 319159f 01ccedb f585a55 01ccedb 58c4fec 01ccedb 58c4fec 805fa80 01ccedb 805fa80 f585a55 4a9efcd |
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
#!/usr/bin/env python3
"""
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
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
print("🏗️ CRANE AI Simple başlatılıyor...")
# GPU sayaçları
gpu_calls = 0
total_calls = 0
@spaces.GPU(duration=60) # 60 saniye GPU
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:
# GPU kontrolü
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()
# Mesaj analizi
message_lower = message.lower()
# Selamlaşma
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)
# Kod yazma
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!"""
# Yapay zeka soruları
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! 🚀"""
# Teknoloji karşılaştırmaları
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!"""
# Test
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}"
# Varsayılan yanıt
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)
# İşlem süresi hesapla
duration = time.time() - start_time
# Yanıtı formatla
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:
# ZeroGPU ile işle
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)}"
# Gradio Chat Interface
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, # ZeroGPU için gerekli
concurrency_limit=2, # Eşzamanlı kullanıcı sınırı
)
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
) |