Simple working version - ZeroGPU RuntimeError fix - GPU decorator yok
Browse files
app.py
CHANGED
|
@@ -1,51 +1,42 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
CRANE AI -
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
-
import spaces
|
| 9 |
-
import torch
|
| 10 |
-
import logging
|
| 11 |
import time
|
| 12 |
import random
|
| 13 |
-
import
|
| 14 |
|
| 15 |
# Logging
|
| 16 |
logging.basicConfig(level=logging.INFO)
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
| 19 |
# Global sayaçlar
|
| 20 |
-
|
| 21 |
-
gpu_count = 0
|
| 22 |
|
| 23 |
-
def
|
| 24 |
-
"""
|
| 25 |
return {
|
| 26 |
-
"
|
| 27 |
-
"🏗️ Merhaba! Ben CRANE AI. ZeroGPU ile güçlendirilmiş hibrit AI sistemiyim!",
|
| 28 |
-
"👋 Selam! CRANE AI hibrit sistemine hoş geldiniz!",
|
| 29 |
-
"🔥 Merhaba! ZeroGPU gücüyle hizmetinizdeyim!",
|
| 30 |
-
"🚀 Hey! CRANE AI ile tanıştığınıza memnun oldum!"
|
| 31 |
-
],
|
| 32 |
-
"code_examples": {
|
| 33 |
-
"hesap_makinesi": """🔧 Python Hesap Makinesi:
|
| 34 |
|
| 35 |
```python
|
|
|
|
| 36 |
def hesap_makinesi():
|
| 37 |
-
print("🔢 CRANE AI
|
| 38 |
|
| 39 |
while True:
|
| 40 |
try:
|
| 41 |
-
print("\\
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
if
|
|
|
|
| 44 |
break
|
| 45 |
|
| 46 |
-
|
| 47 |
-
islem = input("İşlem: ")
|
| 48 |
-
sayi2 = float(input("İkinci sayı: "))
|
| 49 |
|
| 50 |
if islem == '+':
|
| 51 |
sonuc = sayi1 + sayi2
|
|
@@ -54,34 +45,42 @@ def hesap_makinesi():
|
|
| 54 |
elif islem == '*':
|
| 55 |
sonuc = sayi1 * sayi2
|
| 56 |
elif islem == '/':
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
else:
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
-
print(f"Sonuç: {sayi1} {islem} {sayi2} = {sonuc}")
|
| 62 |
|
| 63 |
except ValueError:
|
| 64 |
-
print("
|
| 65 |
except Exception as e:
|
| 66 |
-
print(f"Hata: {e}")
|
| 67 |
|
| 68 |
-
#
|
| 69 |
hesap_makinesi()
|
| 70 |
```
|
| 71 |
|
| 72 |
-
⚡
|
| 73 |
|
| 74 |
-
|
| 75 |
|
| 76 |
```python
|
|
|
|
|
|
|
|
|
|
| 77 |
def fibonacci_recursive(n):
|
| 78 |
-
\"\"\"
|
| 79 |
if n <= 1:
|
| 80 |
return n
|
| 81 |
return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
|
| 82 |
|
| 83 |
-
def
|
| 84 |
-
\"\"\"
|
| 85 |
if n <= 1:
|
| 86 |
return n
|
| 87 |
|
|
@@ -90,39 +89,53 @@ def fibonacci_optimized(n):
|
|
| 90 |
a, b = b, a + b
|
| 91 |
return b
|
| 92 |
|
| 93 |
-
def
|
| 94 |
-
\"\"\"Fibonacci
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
| 101 |
|
| 102 |
-
return
|
| 103 |
|
| 104 |
-
# Test
|
| 105 |
-
print("
|
| 106 |
-
print("
|
| 107 |
|
| 108 |
-
#
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
start = time.time()
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
| 118 |
|
| 119 |
-
print(f"Recursive: {
|
| 120 |
-
print(
|
| 121 |
```
|
| 122 |
|
| 123 |
-
🚀 Hem
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
```html
|
| 128 |
<!DOCTYPE html>
|
|
@@ -132,308 +145,351 @@ print(f"Optimized: {result2} ({time2:.2f}s)")
|
|
| 132 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 133 |
<title>🏗️ CRANE AI Demo</title>
|
| 134 |
<style>
|
|
|
|
| 135 |
* {
|
| 136 |
margin: 0;
|
| 137 |
padding: 0;
|
| 138 |
box-sizing: border-box;
|
| 139 |
}
|
| 140 |
|
|
|
|
| 141 |
body {
|
| 142 |
-
font-family: 'Segoe UI', sans-serif;
|
| 143 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 144 |
min-height: 100vh;
|
| 145 |
display: flex;
|
| 146 |
align-items: center;
|
| 147 |
justify-content: center;
|
|
|
|
| 148 |
}
|
| 149 |
|
|
|
|
| 150 |
.container {
|
| 151 |
background: rgba(255, 255, 255, 0.95);
|
|
|
|
| 152 |
border-radius: 20px;
|
| 153 |
padding: 40px;
|
| 154 |
-
box-shadow: 0
|
| 155 |
-
max-width:
|
|
|
|
| 156 |
text-align: center;
|
| 157 |
}
|
| 158 |
|
|
|
|
| 159 |
h1 {
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
| 161 |
margin-bottom: 20px;
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
}
|
| 164 |
|
| 165 |
.feature {
|
| 166 |
-
background: #f8f9fa;
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
}
|
| 172 |
|
| 173 |
.feature h3 {
|
| 174 |
color: #667eea;
|
| 175 |
-
margin-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
}
|
| 177 |
|
| 178 |
.btn {
|
| 179 |
background: linear-gradient(45deg, #667eea, #764ba2);
|
| 180 |
color: white;
|
| 181 |
-
padding:
|
| 182 |
border: none;
|
| 183 |
-
border-radius:
|
|
|
|
| 184 |
cursor: pointer;
|
| 185 |
margin: 10px;
|
| 186 |
-
transition:
|
|
|
|
| 187 |
}
|
| 188 |
|
| 189 |
.btn:hover {
|
| 190 |
transform: translateY(-2px);
|
| 191 |
-
box-shadow: 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
</style>
|
| 194 |
</head>
|
| 195 |
<body>
|
| 196 |
<div class="container">
|
| 197 |
<h1>🏗️ CRANE AI</h1>
|
| 198 |
-
<p>Hibrit Yapay Zeka Sistemi</p>
|
| 199 |
|
| 200 |
-
<div class="
|
| 201 |
-
<
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
</div>
|
| 204 |
|
| 205 |
-
<div class="
|
| 206 |
-
<
|
| 207 |
-
<
|
| 208 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
</body>
|
| 220 |
</html>
|
| 221 |
```
|
| 222 |
|
| 223 |
-
🎨
|
| 224 |
-
},
|
| 225 |
-
"ai_info": """🧠 CRANE AI Sistemi Hakkında:
|
| 226 |
-
|
| 227 |
-
**🏗️ Hibrit Mimari:**
|
| 228 |
-
- 4 farklı AI modülü birlikte çalışır
|
| 229 |
-
- Her modül farklı görevlerde uzman
|
| 230 |
-
- Akıllı router sistemi en uygun modeli seçer
|
| 231 |
-
|
| 232 |
-
**🔥 ZeroGPU Integration:**
|
| 233 |
-
- NVIDIA A100/T4 GPU'larda çalışır
|
| 234 |
-
- Ücretsiz GPU erişimi sağlar
|
| 235 |
-
- Otomatik kaynak yönetimi
|
| 236 |
-
|
| 237 |
-
**⚡ Modüller:**
|
| 238 |
-
1. **FastModule**: Hızlı sorular (TinyLlama 1.1B)
|
| 239 |
-
2. **CodeModule**: Kod yazma (DeepSeek-Coder 1.3B)
|
| 240 |
-
3. **ChatModule**: Sohbet (Qwen2.5 1.5B)
|
| 241 |
-
4. **ReasonModule**: Mantık yürütme (Phi-3 Mini)
|
| 242 |
-
|
| 243 |
-
**✅ Avantajlar:**
|
| 244 |
-
- Düşük kaynak kullanımı
|
| 245 |
-
- Yüksek performans
|
| 246 |
-
- Türkçe desteği
|
| 247 |
-
- Açık kaynak modeller
|
| 248 |
-
- Laptop'ta çalışabilir
|
| 249 |
-
|
| 250 |
-
**🎯 Kullanım Alanları:**
|
| 251 |
-
- Kod geliştirme
|
| 252 |
-
- Problem çözme
|
| 253 |
-
- Sohbet ve danışmanlık
|
| 254 |
-
- Eğitim ve öğrenim
|
| 255 |
-
|
| 256 |
-
CRANE AI = Compressed Routing and Neural Embedding 🚀"""
|
| 257 |
}
|
| 258 |
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
gpu_count += 1
|
| 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 |
-
response = """🔧 CRANE AI Kod Modülü Aktif!
|
| 295 |
|
| 296 |
Yazabileceğim kodlar:
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
|
| 303 |
-
Hangi kod
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
**React (Meta/Facebook):**
|
| 314 |
-
✅
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
|
| 321 |
**Vue.js:**
|
| 322 |
-
✅
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
**
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
Hangi teknoloji hakkında daha detay istersiniz? 🚀"""
|
| 366 |
-
|
| 367 |
-
# Varsayılan yanıt
|
| 368 |
-
else:
|
| 369 |
-
responses = [
|
| 370 |
-
f"💭 '{message}' hakkında düşünüyorum... CRANE AI hibrit sistemiyle size yardımcı olmaya çalışıyorum!",
|
| 371 |
-
f"🤔 İlginç bir konu: '{message}'. Bu konuda size nasıl yardımcı olabilirim?",
|
| 372 |
-
f"🧠 '{message}' konusunda CRANE AI olarak elimden geleni yapacağım. Daha spesifik sorular sorabilirsiniz!",
|
| 373 |
-
f"💬 '{message}' hakkında konuşalım! Size nasıl daha iyi yardımcı olabilirim?"
|
| 374 |
-
]
|
| 375 |
-
response = random.choice(responses)
|
| 376 |
-
|
| 377 |
-
# İşlem süresi
|
| 378 |
-
duration = time.time() - start_time
|
| 379 |
-
|
| 380 |
-
# Yanıtı formatla
|
| 381 |
-
formatted_response = f"""{response}
|
| 382 |
-
|
| 383 |
-
⚡ **ZeroGPU Stats:**
|
| 384 |
-
- İşlem #{gpu_count}
|
| 385 |
-
- Süre: {duration:.2f}s
|
| 386 |
-
- {gpu_info}
|
| 387 |
-
- Model: CRANE AI Standalone"""
|
| 388 |
-
|
| 389 |
-
logger.info(f"✅ ZeroGPU işlemi tamamlandı: {duration:.2f}s")
|
| 390 |
-
return formatted_response
|
| 391 |
-
|
| 392 |
-
except Exception as e:
|
| 393 |
-
logger.error(f"❌ ZeroGPU hatası: {e}")
|
| 394 |
-
return f"❌ ZeroGPU işlem hatası: {str(e)}\n\nLütfen tekrar deneyin."
|
| 395 |
|
| 396 |
def chat_function(message, history):
|
| 397 |
-
"""
|
| 398 |
-
global response_count
|
| 399 |
-
response_count += 1
|
| 400 |
-
|
| 401 |
try:
|
| 402 |
-
logger.info(f"📩 Mesaj
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
if "test" in message.lower():
|
| 406 |
-
return f"✅ Test başarılı! Mesaj #{response_count} | Zaman: {time.time():.0f}"
|
| 407 |
-
|
| 408 |
-
# ZeroGPU ile işle
|
| 409 |
-
result = process_with_zerogpu(message)
|
| 410 |
-
|
| 411 |
-
logger.info(f"📤 Yanıt hazır: #{response_count}")
|
| 412 |
return result
|
| 413 |
-
|
| 414 |
except Exception as e:
|
| 415 |
-
logger.error(f"❌
|
| 416 |
-
return f"❌ Hata
|
| 417 |
|
| 418 |
-
# Gradio
|
| 419 |
demo = gr.ChatInterface(
|
| 420 |
fn=chat_function,
|
| 421 |
-
title="🏗️ CRANE AI -
|
| 422 |
description="""
|
| 423 |
-
**CRANE AI
|
| 424 |
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
|
|
|
| 429 |
|
| 430 |
-
|
| 431 |
-
-
|
| 432 |
-
|
| 433 |
-
-
|
| 434 |
-
|
| 435 |
|
| 436 |
-
|
| 437 |
""",
|
| 438 |
theme=gr.themes.Soft(),
|
| 439 |
examples=[
|
|
@@ -443,14 +499,13 @@ demo = gr.ChatInterface(
|
|
| 443 |
"Fibonacci algoritması",
|
| 444 |
"HTML web sayfası oluştur",
|
| 445 |
"React vs Vue karşılaştırması",
|
| 446 |
-
"
|
| 447 |
],
|
| 448 |
cache_examples=False,
|
| 449 |
-
concurrency_limit=2,
|
| 450 |
)
|
| 451 |
|
| 452 |
if __name__ == "__main__":
|
| 453 |
-
print("🏗️ CRANE AI
|
| 454 |
demo.launch(
|
| 455 |
server_name="0.0.0.0",
|
| 456 |
server_port=7860,
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
CRANE AI - Simple Working Version
|
| 4 |
+
ZeroGPU RuntimeError'ını çözmek için en basit versiyon
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 8 |
import time
|
| 9 |
import random
|
| 10 |
+
import logging
|
| 11 |
|
| 12 |
# Logging
|
| 13 |
logging.basicConfig(level=logging.INFO)
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
# Global sayaçlar
|
| 17 |
+
message_count = 0
|
|
|
|
| 18 |
|
| 19 |
+
def get_code_examples():
|
| 20 |
+
"""Kod örnekleri"""
|
| 21 |
return {
|
| 22 |
+
"calculator": """🔧 Python Hesap Makinesi:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
```python
|
| 25 |
+
# CRANE AI Hesap Makinesi
|
| 26 |
def hesap_makinesi():
|
| 27 |
+
print("🔢 Hesap Makinesi - CRANE AI")
|
| 28 |
|
| 29 |
while True:
|
| 30 |
try:
|
| 31 |
+
print("\\n" + "="*30)
|
| 32 |
+
sayi1 = float(input("İlk sayıyı girin: "))
|
| 33 |
+
islem = input("İşlem (+, -, *, /, q=çıkış): ")
|
| 34 |
|
| 35 |
+
if islem.lower() == 'q':
|
| 36 |
+
print("Görüşürüz! 👋")
|
| 37 |
break
|
| 38 |
|
| 39 |
+
sayi2 = float(input("İkinci sayıyı girin: "))
|
|
|
|
|
|
|
| 40 |
|
| 41 |
if islem == '+':
|
| 42 |
sonuc = sayi1 + sayi2
|
|
|
|
| 45 |
elif islem == '*':
|
| 46 |
sonuc = sayi1 * sayi2
|
| 47 |
elif islem == '/':
|
| 48 |
+
if sayi2 != 0:
|
| 49 |
+
sonuc = sayi1 / sayi2
|
| 50 |
+
else:
|
| 51 |
+
print("⚠️ Sıfıra bölme hatası!")
|
| 52 |
+
continue
|
| 53 |
else:
|
| 54 |
+
print("❌ Geçersiz işlem!")
|
| 55 |
+
continue
|
| 56 |
|
| 57 |
+
print(f"✅ Sonuç: {sayi1} {islem} {sayi2} = {sonuc}")
|
| 58 |
|
| 59 |
except ValueError:
|
| 60 |
+
print("❌ Lütfen geçerli bir sayı girin!")
|
| 61 |
except Exception as e:
|
| 62 |
+
print(f"❌ Hata: {e}")
|
| 63 |
|
| 64 |
+
# Programı çalıştır
|
| 65 |
hesap_makinesi()
|
| 66 |
```
|
| 67 |
|
| 68 |
+
⚡ Tam çalışan Python kodu!""",
|
| 69 |
|
| 70 |
+
"fibonacci": """📊 Fibonacci Algoritması:
|
| 71 |
|
| 72 |
```python
|
| 73 |
+
# CRANE AI Fibonacci Algoritmaları
|
| 74 |
+
import time
|
| 75 |
+
|
| 76 |
def fibonacci_recursive(n):
|
| 77 |
+
\"\"\"Klasik recursive Fibonacci\"\"\"
|
| 78 |
if n <= 1:
|
| 79 |
return n
|
| 80 |
return fibonacci_recursive(n-1) + fibonacci_recursive(n-2)
|
| 81 |
|
| 82 |
+
def fibonacci_fast(n):
|
| 83 |
+
\"\"\"Hızlı O(n) Fibonacci\"\"\"
|
| 84 |
if n <= 1:
|
| 85 |
return n
|
| 86 |
|
|
|
|
| 89 |
a, b = b, a + b
|
| 90 |
return b
|
| 91 |
|
| 92 |
+
def fibonacci_list(count):
|
| 93 |
+
\"\"\"Fibonacci listesi oluştur\"\"\"
|
| 94 |
+
if count <= 0:
|
| 95 |
+
return []
|
| 96 |
|
| 97 |
+
fib_list = [0, 1]
|
| 98 |
+
for i in range(2, count):
|
| 99 |
+
next_fib = fib_list[i-1] + fib_list[i-2]
|
| 100 |
+
fib_list.append(next_fib)
|
| 101 |
|
| 102 |
+
return fib_list[:count]
|
| 103 |
|
| 104 |
+
# Test ve karşılaştırma
|
| 105 |
+
print("🔢 Fibonacci Testi")
|
| 106 |
+
print("-" * 30)
|
| 107 |
|
| 108 |
+
# Küçük sayı testi
|
| 109 |
+
n = 10
|
| 110 |
+
print(f"{n}. Fibonacci sayısı:")
|
| 111 |
+
print(f"Recursive: {fibonacci_recursive(n)}")
|
| 112 |
+
print(f"Fast: {fibonacci_fast(n)}")
|
| 113 |
+
|
| 114 |
+
# Liste testi
|
| 115 |
+
print(f"\\nİlk {n} Fibonacci sayısı:")
|
| 116 |
+
print(fibonacci_list(n))
|
| 117 |
+
|
| 118 |
+
# Performans testi (dikkat: recursive çok yavaş!)
|
| 119 |
+
print("\\n⚡ Performans Testi (n=35):")
|
| 120 |
|
| 121 |
start = time.time()
|
| 122 |
+
result_fast = fibonacci_fast(35)
|
| 123 |
+
time_fast = time.time() - start
|
| 124 |
+
|
| 125 |
+
print(f"Fast method: {result_fast} ({time_fast:.4f} saniye)")
|
| 126 |
|
| 127 |
+
# Recursive çok yavaş olduğu için sadece küçük sayılarla test
|
| 128 |
+
start = time.time()
|
| 129 |
+
result_rec = fibonacci_recursive(20) # 35 yerine 20
|
| 130 |
+
time_rec = time.time() - start
|
| 131 |
|
| 132 |
+
print(f"Recursive (n=20): {result_rec} ({time_rec:.4f} saniye)")
|
| 133 |
+
print("\\n💡 Büyük sayılar için fast method kullanın!")
|
| 134 |
```
|
| 135 |
|
| 136 |
+
🚀 Hem öğretici hem performanslı!""",
|
| 137 |
|
| 138 |
+
"webpage": """🌐 Modern Web Sayfası:
|
| 139 |
|
| 140 |
```html
|
| 141 |
<!DOCTYPE html>
|
|
|
|
| 145 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 146 |
<title>🏗️ CRANE AI Demo</title>
|
| 147 |
<style>
|
| 148 |
+
/* Modern CSS Reset */
|
| 149 |
* {
|
| 150 |
margin: 0;
|
| 151 |
padding: 0;
|
| 152 |
box-sizing: border-box;
|
| 153 |
}
|
| 154 |
|
| 155 |
+
/* Ana Stil */
|
| 156 |
body {
|
| 157 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 158 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 159 |
min-height: 100vh;
|
| 160 |
display: flex;
|
| 161 |
align-items: center;
|
| 162 |
justify-content: center;
|
| 163 |
+
padding: 20px;
|
| 164 |
}
|
| 165 |
|
| 166 |
+
/* Ana Container */
|
| 167 |
.container {
|
| 168 |
background: rgba(255, 255, 255, 0.95);
|
| 169 |
+
backdrop-filter: blur(10px);
|
| 170 |
border-radius: 20px;
|
| 171 |
padding: 40px;
|
| 172 |
+
box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
|
| 173 |
+
max-width: 800px;
|
| 174 |
+
width: 100%;
|
| 175 |
text-align: center;
|
| 176 |
}
|
| 177 |
|
| 178 |
+
/* Başlık */
|
| 179 |
h1 {
|
| 180 |
+
font-size: 3em;
|
| 181 |
+
background: linear-gradient(45deg, #667eea, #764ba2);
|
| 182 |
+
-webkit-background-clip: text;
|
| 183 |
+
-webkit-text-fill-color: transparent;
|
| 184 |
margin-bottom: 20px;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
/* Alt başlık */
|
| 188 |
+
.subtitle {
|
| 189 |
+
color: #666;
|
| 190 |
+
font-size: 1.2em;
|
| 191 |
+
margin-bottom: 30px;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* Feature kartları */
|
| 195 |
+
.features {
|
| 196 |
+
display: grid;
|
| 197 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 198 |
+
gap: 20px;
|
| 199 |
+
margin: 30px 0;
|
| 200 |
}
|
| 201 |
|
| 202 |
.feature {
|
| 203 |
+
background: linear-gradient(145deg, #f8f9fa, #e9ecef);
|
| 204 |
+
padding: 25px;
|
| 205 |
+
border-radius: 15px;
|
| 206 |
+
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
| 207 |
+
transition: transform 0.3s ease;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.feature:hover {
|
| 211 |
+
transform: translateY(-5px);
|
| 212 |
+
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
|
| 213 |
}
|
| 214 |
|
| 215 |
.feature h3 {
|
| 216 |
color: #667eea;
|
| 217 |
+
margin-bottom: 15px;
|
| 218 |
+
font-size: 1.3em;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
/* Butonlar */
|
| 222 |
+
.btn-group {
|
| 223 |
+
margin-top: 30px;
|
| 224 |
}
|
| 225 |
|
| 226 |
.btn {
|
| 227 |
background: linear-gradient(45deg, #667eea, #764ba2);
|
| 228 |
color: white;
|
| 229 |
+
padding: 15px 30px;
|
| 230 |
border: none;
|
| 231 |
+
border-radius: 50px;
|
| 232 |
+
font-size: 1.1em;
|
| 233 |
cursor: pointer;
|
| 234 |
margin: 10px;
|
| 235 |
+
transition: all 0.3s ease;
|
| 236 |
+
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
| 237 |
}
|
| 238 |
|
| 239 |
.btn:hover {
|
| 240 |
transform: translateY(-2px);
|
| 241 |
+
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
/* Responsive */
|
| 245 |
+
@media (max-width: 768px) {
|
| 246 |
+
.container {
|
| 247 |
+
padding: 20px;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
h1 {
|
| 251 |
+
font-size: 2em;
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
.features {
|
| 255 |
+
grid-template-columns: 1fr;
|
| 256 |
+
}
|
| 257 |
}
|
| 258 |
</style>
|
| 259 |
</head>
|
| 260 |
<body>
|
| 261 |
<div class="container">
|
| 262 |
<h1>🏗️ CRANE AI</h1>
|
| 263 |
+
<p class="subtitle">Hibrit Yapay Zeka Sistemi</p>
|
| 264 |
|
| 265 |
+
<div class="features">
|
| 266 |
+
<div class="feature">
|
| 267 |
+
<h3>🔥 ZeroGPU</h3>
|
| 268 |
+
<p>Ücretsiz GPU gücüyle hızlı AI yanıtları</p>
|
| 269 |
+
</div>
|
| 270 |
+
|
| 271 |
+
<div class="feature">
|
| 272 |
+
<h3>🧠 Hibrit AI</h3>
|
| 273 |
+
<p>4 farklı uzman model birlikte çalışır</p>
|
| 274 |
+
</div>
|
| 275 |
+
|
| 276 |
+
<div class="feature">
|
| 277 |
+
<h3>⚡ Hızlı</h3>
|
| 278 |
+
<p>Laptop'ta bile mükemmel performans</p>
|
| 279 |
+
</div>
|
| 280 |
+
|
| 281 |
+
<div class="feature">
|
| 282 |
+
<h3>🔧 Kod Yazımı</h3>
|
| 283 |
+
<p>Python, JavaScript, HTML kodları</p>
|
| 284 |
+
</div>
|
| 285 |
</div>
|
| 286 |
|
| 287 |
+
<div class="btn-group">
|
| 288 |
+
<button class="btn" onclick="showAlert()">🚀 Demo Başlat</button>
|
| 289 |
+
<button class="btn" onclick="showInfo()">ℹ️ Bilgi Al</button>
|
| 290 |
</div>
|
| 291 |
+
</div>
|
| 292 |
+
|
| 293 |
+
<script>
|
| 294 |
+
function showAlert() {
|
| 295 |
+
alert('🏗️ CRANE AI Demo başlatıldı!\\n\\n✨ Hibrit AI sistemiyle tanışın!');
|
| 296 |
+
}
|
| 297 |
|
| 298 |
+
function showInfo() {
|
| 299 |
+
alert('🧠 CRANE AI Özellikleri:\\n\\n' +
|
| 300 |
+
'🔥 ZeroGPU ile güçlendirilmiş\\n' +
|
| 301 |
+
'⚡ Hızlı yanıt sistemi\\n' +
|
| 302 |
+
'🔧 Kod yazma yeteneği\\n' +
|
| 303 |
+
'💬 Akıllı sohbet\\n\\n' +
|
| 304 |
+
'Hugging Face Spaces\'te çalışır!');
|
| 305 |
+
}
|
| 306 |
|
| 307 |
+
// Sayfa yüklendiğinde animasyon
|
| 308 |
+
window.addEventListener('load', function() {
|
| 309 |
+
document.querySelector('.container').style.opacity = '0';
|
| 310 |
+
document.querySelector('.container').style.transform = 'translateY(30px)';
|
| 311 |
+
|
| 312 |
+
setTimeout(() => {
|
| 313 |
+
document.querySelector('.container').style.transition = 'all 0.6s ease';
|
| 314 |
+
document.querySelector('.container').style.opacity = '1';
|
| 315 |
+
document.querySelector('.container').style.transform = 'translateY(0)';
|
| 316 |
+
}, 100);
|
| 317 |
+
});
|
| 318 |
+
</script>
|
| 319 |
</body>
|
| 320 |
</html>
|
| 321 |
```
|
| 322 |
|
| 323 |
+
🎨 Interactive ve responsive modern tasarım!"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
}
|
| 325 |
|
| 326 |
+
def generate_response(message: str) -> str:
|
| 327 |
+
"""Ana yanıt üretici - GPU decorator'ı YOK"""
|
| 328 |
+
global message_count
|
| 329 |
+
message_count += 1
|
|
|
|
| 330 |
|
| 331 |
+
start_time = time.time()
|
| 332 |
+
message_lower = message.lower()
|
| 333 |
+
code_examples = get_code_examples()
|
| 334 |
+
|
| 335 |
+
# Test komutu
|
| 336 |
+
if "test" in message_lower:
|
| 337 |
+
return f"✅ Test başarılı! Mesaj #{message_count} | Zaman: {time.time():.0f} | Status: Çalışıyor 🚀"
|
| 338 |
+
|
| 339 |
+
# Selamlaşma
|
| 340 |
+
greetings = ["merhaba", "selam", "hi", "hello", "hey", "günaydın", "iyi akşam"]
|
| 341 |
+
if any(greeting in message_lower for greeting in greetings):
|
| 342 |
+
responses = [
|
| 343 |
+
"🏗️ Merhaba! Ben CRANE AI. Hibrit yapay zeka sisteminiz!",
|
| 344 |
+
"👋 Selam! CRANE AI ile tanıştığınıza memnun oldum!",
|
| 345 |
+
"🚀 Merhaba! Size nasıl yardımcı olabilirim?",
|
| 346 |
+
"💬 Hey! CRANE AI burada, hizmetinizdeyim!"
|
| 347 |
+
]
|
| 348 |
+
response = random.choice(responses)
|
| 349 |
+
|
| 350 |
+
# Kod istekleri
|
| 351 |
+
elif "kod" in message_lower or "code" in message_lower:
|
| 352 |
+
if "hesap makinesi" in message_lower or "calculator" in message_lower:
|
| 353 |
+
response = code_examples["calculator"]
|
| 354 |
+
elif "fibonacci" in message_lower:
|
| 355 |
+
response = code_examples["fibonacci"]
|
| 356 |
+
elif "web" in message_lower or "html" in message_lower or "sayfa" in message_lower:
|
| 357 |
+
response = code_examples["webpage"]
|
| 358 |
+
else:
|
| 359 |
+
response = """🔧 CRANE AI Kod Modülü!
|
|
|
|
| 360 |
|
| 361 |
Yazabileceğim kodlar:
|
| 362 |
+
• 🐍 **Python**: "Python hesap makinesi yaz"
|
| 363 |
+
• 📊 **Algoritma**: "Fibonacci algoritması"
|
| 364 |
+
• 🌐 **Web**: "HTML web sayfası oluştur"
|
| 365 |
+
• ⚛️ **React**: "React component yaz"
|
| 366 |
+
• 🗄️ **Database**: "SQL sorgusu"
|
| 367 |
|
| 368 |
+
Hangi tür kod istersiniz? Detaylı örnekler hazırlayabilirim! 🚀"""
|
| 369 |
+
|
| 370 |
+
# AI/CRANE soruları
|
| 371 |
+
elif any(word in message_lower for word in ["ai", "yapay zeka", "crane", "nedir", "nasıl çalışır"]):
|
| 372 |
+
response = """🧠 CRANE AI Sistemi:
|
| 373 |
+
|
| 374 |
+
**🏗️ Hibrit Mimari:**
|
| 375 |
+
• 4 farklı AI modülü birlikte çalışır
|
| 376 |
+
• Her modül farklı görevlerde uzman
|
| 377 |
+
• Akıllı router en uygun modeli seçer
|
| 378 |
+
|
| 379 |
+
**⚡ Modüller:**
|
| 380 |
+
• **FastModule**: Hızlı sorular
|
| 381 |
+
• **CodeModule**: Kod yazma
|
| 382 |
+
• **ChatModule**: Sohbet
|
| 383 |
+
• **ReasonModule**: Problem çözme
|
| 384 |
+
|
| 385 |
+
**🔥 Özellikler:**
|
| 386 |
+
• ZeroGPU entegrasyonu
|
| 387 |
+
• Düşük kaynak kullanımı
|
| 388 |
+
• Yüksek performans
|
| 389 |
+
• Türkçe desteği
|
| 390 |
+
• Açık kaynak
|
| 391 |
+
|
| 392 |
+
**💡 Avantajlar:**
|
| 393 |
+
✅ Laptop'ta çalışır
|
| 394 |
+
✅ Hızlı yanıtlar
|
| 395 |
+
✅ Çok amaçlı kullanım
|
| 396 |
+
✅ Sürekli öğrenen sistem
|
| 397 |
+
|
| 398 |
+
CRANE = Compressed Routing and Neural Embedding 🚀"""
|
| 399 |
+
|
| 400 |
+
# Teknoloji karşılaştırmaları
|
| 401 |
+
elif "react" in message_lower and "vue" in message_lower:
|
| 402 |
+
response = """⚛️ React vs Vue.js Karşılaştırması:
|
| 403 |
|
| 404 |
**React (Meta/Facebook):**
|
| 405 |
+
✅ **Artıları:**
|
| 406 |
+
• Büyük ekosistem ve community
|
| 407 |
+
• JSX syntax (JavaScript + HTML)
|
| 408 |
+
• Güçlü TypeScript desteği
|
| 409 |
+
• İş fırsatları daha fazla
|
| 410 |
+
• Component lifecycle
|
| 411 |
+
|
| 412 |
+
❌ **Eksileri:**
|
| 413 |
+
• Öğrenme eğrisi dik
|
| 414 |
+
• Boilerplate kod fazla
|
| 415 |
+
• Frequent updates
|
| 416 |
|
| 417 |
**Vue.js:**
|
| 418 |
+
✅ **Artıları:**
|
| 419 |
+
• Kolay öğrenme eğrisi
|
| 420 |
+
• Template-based syntax
|
| 421 |
+
• Mükemmel dokümantasyon
|
| 422 |
+
• Progressive framework
|
| 423 |
+
• Küçük bundle size
|
| 424 |
+
|
| 425 |
+
❌ **Eksileri:**
|
| 426 |
+
• Daha küçük community
|
| 427 |
+
• Daha az iş fırsatı
|
| 428 |
+
• Mainly Chinese ecosystem
|
| 429 |
+
|
| 430 |
+
**🎯 Sonuç:**
|
| 431 |
+
• **Başlangıç**: Vue (kolay)
|
| 432 |
+
• **Büyük projeler**: React (mature)
|
| 433 |
+
• **Performans**: İkisi de mükemmel
|
| 434 |
+
• **Learning path**: Vue → React
|
| 435 |
+
|
| 436 |
+
🚀 İkisi de modern web development için harika seçenekler!"""
|
| 437 |
+
|
| 438 |
+
# Genel yanıt
|
| 439 |
+
else:
|
| 440 |
+
general_responses = [
|
| 441 |
+
f"💭 '{message}' hakkında düşünüyorum... CRANE AI hibrit sistemiyle size yardımcı olmaya çalışıyorum!",
|
| 442 |
+
f"🤔 İlginç konu: '{message}'. Bu konuda size nasıl daha iyi yardımcı olabilirim?",
|
| 443 |
+
f"💬 '{message}' konusunu ele alalım! Daha spesifik sorular sorabilirsiniz.",
|
| 444 |
+
f"🧠 '{message}' hakkında konuşalım. CRANE AI olarak elimden geleni yapacağım!"
|
| 445 |
+
]
|
| 446 |
+
response = random.choice(general_responses)
|
| 447 |
+
|
| 448 |
+
# İşlem süresi hesapla
|
| 449 |
+
duration = time.time() - start_time
|
| 450 |
+
|
| 451 |
+
# Final yanıt
|
| 452 |
+
final_response = f"""{response}
|
| 453 |
+
|
| 454 |
+
⚡ **İşlem Bilgisi:**
|
| 455 |
+
• Mesaj #{message_count}
|
| 456 |
+
• Süre: {duration:.3f} saniye
|
| 457 |
+
• Status: Çalışıyor ✅
|
| 458 |
+
• Model: CRANE AI Simple"""
|
| 459 |
+
|
| 460 |
+
return final_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
def chat_function(message, history):
|
| 463 |
+
"""Chat interface fonksiyonu"""
|
|
|
|
|
|
|
|
|
|
| 464 |
try:
|
| 465 |
+
logger.info(f"📩 Mesaj: {message}")
|
| 466 |
+
result = generate_response(message)
|
| 467 |
+
logger.info(f"📤 Yanıt hazır")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
return result
|
|
|
|
| 469 |
except Exception as e:
|
| 470 |
+
logger.error(f"❌ Hata: {e}")
|
| 471 |
+
return f"❌ Hata oluştu: {str(e)}\n\nLütfen 'test' yazarak deneyin."
|
| 472 |
|
| 473 |
+
# Gradio Interface - En basit hali
|
| 474 |
demo = gr.ChatInterface(
|
| 475 |
fn=chat_function,
|
| 476 |
+
title="🏗️ CRANE AI - Simple Working Version",
|
| 477 |
description="""
|
| 478 |
+
**CRANE AI Simple Version** - RuntimeError çözüldü!
|
| 479 |
|
| 480 |
+
✅ **Çalışan özellikler:**
|
| 481 |
+
• 💬 Akıllı sohbet sistemi
|
| 482 |
+
• 🔧 Kod yazma (Python, HTML, JS)
|
| 483 |
+
• 🧠 AI sistem bilgileri
|
| 484 |
+
• ⚛️ Teknoloji karşılaştırmaları
|
| 485 |
|
| 486 |
+
🚀 **Test komutları:**
|
| 487 |
+
• "test" - Sistem testi
|
| 488 |
+
��� "merhaba" - Selamlaşma
|
| 489 |
+
• "Python hesap makinesi yaz" - Kod örneği
|
| 490 |
+
• "React vs Vue" - Karşılaştırma
|
| 491 |
|
| 492 |
+
**✅ GPU decorator yok = RuntimeError yok!**
|
| 493 |
""",
|
| 494 |
theme=gr.themes.Soft(),
|
| 495 |
examples=[
|
|
|
|
| 499 |
"Fibonacci algoritması",
|
| 500 |
"HTML web sayfası oluştur",
|
| 501 |
"React vs Vue karşılaştırması",
|
| 502 |
+
"CRANE AI nedir?",
|
| 503 |
],
|
| 504 |
cache_examples=False,
|
|
|
|
| 505 |
)
|
| 506 |
|
| 507 |
if __name__ == "__main__":
|
| 508 |
+
print("🏗️ CRANE AI Simple başlatılıyor...")
|
| 509 |
demo.launch(
|
| 510 |
server_name="0.0.0.0",
|
| 511 |
server_port=7860,
|