Debug version - hataları görmek için
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
CRANE AI -
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
@@ -10,428 +10,178 @@ import torch
|
|
| 10 |
import logging
|
| 11 |
import os
|
| 12 |
import time
|
|
|
|
| 13 |
|
| 14 |
# Logging
|
| 15 |
-
logging.basicConfig(level=logging.
|
| 16 |
logger = logging.getLogger(__name__)
|
| 17 |
|
| 18 |
-
# ZeroGPU için import'lar
|
| 19 |
-
from config.settings import MODELS
|
| 20 |
-
from modules.fast_module import FastModule
|
| 21 |
-
|
| 22 |
# Global değişkenler
|
| 23 |
model_cache = {}
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
global model_cache
|
| 29 |
-
|
| 30 |
-
if "fast_module" in model_cache:
|
| 31 |
-
return model_cache["fast_module"]
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
try:
|
| 40 |
-
# Sadece hızlı modeli yükle (GPU memory limiti için)
|
| 41 |
-
fast_config = {
|
| 42 |
-
**MODELS["fast_module"],
|
| 43 |
-
"device": device,
|
| 44 |
-
"hf_token": os.getenv("HF_TOKEN", "")
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
module = FastModule(fast_config)
|
| 48 |
-
|
| 49 |
-
# Senkron model yükleme
|
| 50 |
-
import asyncio
|
| 51 |
-
loop = asyncio.new_event_loop()
|
| 52 |
-
asyncio.set_event_loop(loop)
|
| 53 |
-
try:
|
| 54 |
-
loop.run_until_complete(module.load_model())
|
| 55 |
-
finally:
|
| 56 |
-
loop.close()
|
| 57 |
-
|
| 58 |
-
model_cache["fast_module"] = module
|
| 59 |
-
logger.info("🔥 Model GPU'da yüklendi")
|
| 60 |
-
return module
|
| 61 |
-
|
| 62 |
-
except Exception as e:
|
| 63 |
-
logger.error(f"❌ Model yükleme hatası: {e}")
|
| 64 |
-
return None
|
| 65 |
-
|
| 66 |
-
@spaces.GPU(duration=60) # 1 dakika GPU
|
| 67 |
-
def process_with_gpu(message: str) -> str:
|
| 68 |
-
"""GPU'da mesaj işler"""
|
| 69 |
-
try:
|
| 70 |
-
# Model yükle
|
| 71 |
-
module = initialize_gpu_model()
|
| 72 |
-
if not module:
|
| 73 |
-
return "⚠️ Model yüklenemedi. Lütfen tekrar deneyin."
|
| 74 |
-
|
| 75 |
-
start_time = time.time()
|
| 76 |
-
|
| 77 |
-
# Basit yanıt üretimi
|
| 78 |
-
message_lower = message.lower()
|
| 79 |
-
|
| 80 |
-
# Selamlaşma kontrolü
|
| 81 |
-
greetings = ["merhaba", "selam", "hi", "hello", "hey", "günaydın", "iyi akşam"]
|
| 82 |
-
if any(greeting in message_lower for greeting in greetings):
|
| 83 |
-
responses = [
|
| 84 |
-
"🏗️ Merhaba! Ben CRANE AI. Size nasıl yardımcı olabilirim?",
|
| 85 |
-
"👋 Selam! CRANE AI hibrit sistemine hoş geldiniz!",
|
| 86 |
-
"🔥 Merhaba! ZeroGPU gücüyle hizmetinizdeyim!"
|
| 87 |
-
]
|
| 88 |
-
import random
|
| 89 |
-
return random.choice(responses)
|
| 90 |
-
|
| 91 |
-
# Kod talebi kontrolü
|
| 92 |
-
code_keywords = ["kod", "code", "python", "javascript", "function", "def", "class", "import"]
|
| 93 |
-
if any(keyword in message_lower for keyword in code_keywords):
|
| 94 |
-
if "hesap makinesi" in message_lower or "calculator" in message_lower:
|
| 95 |
-
return """🔧 Python Hesap Makinesi:
|
| 96 |
|
| 97 |
```python
|
| 98 |
def hesap_makinesi():
|
| 99 |
print("Basit Hesap Makinesi")
|
| 100 |
-
print("İşlemler: +, -, *, /")
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
sonuc = sayi1 / sayi2
|
| 117 |
-
else:
|
| 118 |
-
print("Sıfıra bölme hatası!")
|
| 119 |
-
continue
|
| 120 |
-
else:
|
| 121 |
-
print("Geçersiz işlem!")
|
| 122 |
-
continue
|
| 123 |
-
|
| 124 |
-
print(f"Sonuç: {sayi1} {islem} {sayi2} = {sonuc}")
|
| 125 |
-
|
| 126 |
-
devam = input("Devam etmek istiyor musunuz? (e/h): ")
|
| 127 |
-
if devam.lower() != 'e':
|
| 128 |
-
break
|
| 129 |
-
|
| 130 |
-
except ValueError:
|
| 131 |
-
print("Lütfen geçerli bir sayı girin!")
|
| 132 |
|
| 133 |
-
# Kullanım
|
| 134 |
hesap_makinesi()
|
| 135 |
```
|
| 136 |
|
| 137 |
-
⚡
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
return n
|
| 147 |
-
return fibonacci(n-1) + fibonacci(n-2)
|
| 148 |
|
| 149 |
-
|
| 150 |
-
\"\"\"Optimized Fibonacci (Dynamic Programming)\"\"\"
|
| 151 |
-
if n <= 1:
|
| 152 |
-
return n
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
a, b = b, a + b
|
| 157 |
-
return b
|
| 158 |
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
elif count == 1:
|
| 164 |
-
return [0]
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
fib_list.append(fib_list[i-1] + fib_list[i-2])
|
| 169 |
-
return fib_list
|
| 170 |
-
|
| 171 |
-
# Kullanım örnekleri
|
| 172 |
-
print("10. Fibonacci sayısı:", fibonacci_optimized(10))
|
| 173 |
-
print("İlk 10 Fibonacci sayısı:", fibonacci_list(10))
|
| 174 |
-
```
|
| 175 |
-
|
| 176 |
-
🚀 Hem recursive hem de optimize edilmiş versiyonlar!"""
|
| 177 |
-
|
| 178 |
-
elif "web" in message_lower or "html" in message_lower:
|
| 179 |
-
return """🌐 Basit Web Sayfası:
|
| 180 |
-
|
| 181 |
-
```html
|
| 182 |
-
<!DOCTYPE html>
|
| 183 |
-
<html lang="tr">
|
| 184 |
-
<head>
|
| 185 |
-
<meta charset="UTF-8">
|
| 186 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 187 |
-
<title>CRANE AI Demo</title>
|
| 188 |
-
<style>
|
| 189 |
-
body {
|
| 190 |
-
font-family: Arial, sans-serif;
|
| 191 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 192 |
-
margin: 0;
|
| 193 |
-
padding: 20px;
|
| 194 |
-
min-height: 100vh;
|
| 195 |
-
}
|
| 196 |
-
.container {
|
| 197 |
-
max-width: 800px;
|
| 198 |
-
margin: 0 auto;
|
| 199 |
-
background: white;
|
| 200 |
-
border-radius: 10px;
|
| 201 |
-
padding: 30px;
|
| 202 |
-
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
| 203 |
-
}
|
| 204 |
-
h1 {
|
| 205 |
-
color: #333;
|
| 206 |
-
text-align: center;
|
| 207 |
-
margin-bottom: 30px;
|
| 208 |
-
}
|
| 209 |
-
.card {
|
| 210 |
-
background: #f8f9fa;
|
| 211 |
-
padding: 20px;
|
| 212 |
-
border-radius: 8px;
|
| 213 |
-
margin: 20px 0;
|
| 214 |
-
border-left: 4px solid #667eea;
|
| 215 |
-
}
|
| 216 |
-
</style>
|
| 217 |
-
</head>
|
| 218 |
-
<body>
|
| 219 |
-
<div class="container">
|
| 220 |
-
<h1>🏗️ CRANE AI Sistemi</h1>
|
| 221 |
-
<div class="card">
|
| 222 |
-
<h3>Hibrit AI Mimarisi</h3>
|
| 223 |
-
<p>Birden fazla küçük model birlikte çalışır.</p>
|
| 224 |
-
</div>
|
| 225 |
-
<div class="card">
|
| 226 |
-
<h3>ZeroGPU Powered</h3>
|
| 227 |
-
<p>Ücretsiz GPU gücüyle hızlı yanıtlar.</p>
|
| 228 |
-
</div>
|
| 229 |
-
</div>
|
| 230 |
-
</body>
|
| 231 |
-
</html>
|
| 232 |
-
```
|
| 233 |
-
|
| 234 |
-
🎨 Modern ve responsive tasarım!"""
|
| 235 |
-
|
| 236 |
-
else:
|
| 237 |
-
return f"""🔧 Kod modülü aktiv!
|
| 238 |
-
|
| 239 |
-
İstediğiniz programlama dilinde kod yazabilirim:
|
| 240 |
-
- 🐍 Python
|
| 241 |
-
- 🟨 JavaScript
|
| 242 |
-
- 🌐 HTML/CSS
|
| 243 |
-
- 🗄️ SQL
|
| 244 |
-
- ⚛️ React
|
| 245 |
-
- 🖥️ ve daha fazlası...
|
| 246 |
-
|
| 247 |
-
Örnek: "Python'da bir hesap makinesi yaz" veya "HTML ile web sayfası oluştur"
|
| 248 |
-
|
| 249 |
-
⚡ ZeroGPU gücüyle hızlı kod üretimi!"""
|
| 250 |
|
| 251 |
-
#
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
return """🧠 Yapay Zeka ve CRANE AI:
|
| 255 |
-
|
| 256 |
-
**CRANE AI Sistemi:**
|
| 257 |
-
- 🏗️ **Hibrit Mimari**: Birden fazla küçük model birlikte çalışır
|
| 258 |
-
- 🔥 **ZeroGPU**: Ücretsiz GPU gücü kullanır
|
| 259 |
-
- 🎯 **Akıllı Router**: Görevlere göre en uygun modeli seçer
|
| 260 |
-
- ⚡ **Hızlı Yanıt**: Optimize edilmiş performans
|
| 261 |
-
|
| 262 |
-
**AI Modelleri:**
|
| 263 |
-
- **FastModule**: TinyLlama 1.1B (hızlı sorular)
|
| 264 |
-
- **CodeModule**: DeepSeek-Coder 1.3B (kod yazma)
|
| 265 |
-
- **ChatModule**: Qwen2.5 1.5B (sohbet)
|
| 266 |
-
- **ReasonModule**: Phi-3 Mini (mantık yürütme)
|
| 267 |
-
|
| 268 |
-
**Avantajları:**
|
| 269 |
-
✅ Laptop'ta çalışabilir
|
| 270 |
-
✅ Düşük kaynak kullanımı
|
| 271 |
-
✅ Yüksek performans
|
| 272 |
-
✅ Açık kaynak modeller
|
| 273 |
-
✅ Türkçe desteği
|
| 274 |
-
|
| 275 |
-
**Nasıl Çalışır?**
|
| 276 |
-
1. Sorgunuz Router'a gelir
|
| 277 |
-
2. En uygun model seçilir
|
| 278 |
-
3. GPU'da hızla işlenir
|
| 279 |
-
4. Optimize edilmiş yanıt döner
|
| 280 |
-
|
| 281 |
-
Yapay zeka geleceğin teknolojisi! 🚀"""
|
| 282 |
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
return """⚛️ React vs Vue Karşılaştırması:
|
| 288 |
-
|
| 289 |
-
**React:**
|
| 290 |
-
✅ **Avantajları:**
|
| 291 |
-
- Facebook desteği
|
| 292 |
-
- Büyük ekosistem
|
| 293 |
-
- JSX syntax
|
| 294 |
-
- Component-based
|
| 295 |
-
- Strong TypeScript support
|
| 296 |
-
|
| 297 |
-
❌ **Dezavantajları:**
|
| 298 |
-
- Steep learning curve
|
| 299 |
-
- Boilerplate kod
|
| 300 |
-
- Frequent updates
|
| 301 |
-
|
| 302 |
-
**Vue:**
|
| 303 |
-
✅ **Avantajları:**
|
| 304 |
-
- Kolay öğrenme
|
| 305 |
-
- Template syntax
|
| 306 |
-
- Excellent documentation
|
| 307 |
-
- Progressive framework
|
| 308 |
-
- Smaller bundle size
|
| 309 |
-
|
| 310 |
-
❌ **Dezavantajları:**
|
| 311 |
-
- Smaller community
|
| 312 |
-
- Less job opportunities
|
| 313 |
-
- Mainly Chinese community
|
| 314 |
-
|
| 315 |
-
**Sonuç:**
|
| 316 |
-
- **Başlangıç**: Vue daha kolay
|
| 317 |
-
- **Büyük projeler**: React daha uygun
|
| 318 |
-
- **Performans**: İkisi de mükemmel
|
| 319 |
-
- **Ekosistem**: React daha zengin
|
| 320 |
-
|
| 321 |
-
🚀 Her ikisi de modern web development için harika!"""
|
| 322 |
-
|
| 323 |
-
else:
|
| 324 |
-
return """💻 Web Development Teknolojileri:
|
| 325 |
-
|
| 326 |
-
**Frontend Frameworks:**
|
| 327 |
-
- ⚛️ React - Component-based UI
|
| 328 |
-
- 🟢 Vue.js - Progressive framework
|
| 329 |
-
- 🅰️ Angular - Full framework
|
| 330 |
-
- ⚡ Svelte - Compile-time optimized
|
| 331 |
-
|
| 332 |
-
**Backend Technologies:**
|
| 333 |
-
- 🟢 Node.js - JavaScript runtime
|
| 334 |
-
- 🐍 Python (Django/Flask)
|
| 335 |
-
- ☕ Java (Spring)
|
| 336 |
-
- 🦀 Rust (Actix/Warp)
|
| 337 |
-
|
| 338 |
-
**Database Options:**
|
| 339 |
-
- 🗄️ PostgreSQL - Relational
|
| 340 |
-
- 🍃 MongoDB - NoSQL
|
| 341 |
-
- ⚡ Redis - In-memory
|
| 342 |
-
- 🔥 Firebase - Real-time
|
| 343 |
-
|
| 344 |
-
**Modern Tools:**
|
| 345 |
-
- 📦 Vite/Webpack - Bundlers
|
| 346 |
-
- 🎨 Tailwind CSS - Utility-first
|
| 347 |
-
- 📝 TypeScript - Type safety
|
| 348 |
-
- 🐳 Docker - Containerization
|
| 349 |
-
|
| 350 |
-
Hangi teknoloji hakkında daha detaylı bilgi istersiniz? 🚀"""
|
| 351 |
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
import asyncio
|
| 356 |
-
loop = asyncio.new_event_loop()
|
| 357 |
-
asyncio.set_event_loop(loop)
|
| 358 |
-
try:
|
| 359 |
-
prompt = f"Kullanıcı: {message}\nYanıt:"
|
| 360 |
-
response = loop.run_until_complete(
|
| 361 |
-
module.generate_response(prompt, max_tokens=200)
|
| 362 |
-
)
|
| 363 |
-
|
| 364 |
-
# Prompt'u temizle
|
| 365 |
-
if "Yanıt:" in response:
|
| 366 |
-
response = response.split("Yanıt:")[-1].strip()
|
| 367 |
-
if "Kullanıcı:" in response:
|
| 368 |
-
response = response.split("Kullanıcı:")[0].strip()
|
| 369 |
-
|
| 370 |
-
finally:
|
| 371 |
-
loop.close()
|
| 372 |
-
|
| 373 |
-
duration = time.time() - start_time
|
| 374 |
-
|
| 375 |
-
if response and len(response.strip()) > 10:
|
| 376 |
-
return f"💬 {response.strip()}\n\n⚡ İşlem süresi: {duration:.2f}s (ZeroGPU)"
|
| 377 |
-
else:
|
| 378 |
-
return "🤔 Bu konuda daha detaylı bilgi verebilmek için sorunuzu biraz daha açabilir misiniz?"
|
| 379 |
-
|
| 380 |
-
except Exception as e:
|
| 381 |
-
logger.error(f"Model çalıştırma hatası: {e}")
|
| 382 |
-
duration = time.time() - start_time
|
| 383 |
-
return f"💭 İlginç bir soru! Bu konuda şöyle düşünüyorum: Bu konu hakkında daha fazla araştırma yapabilirim. Size başka nasıl yardımcı olabilirim?\n\n⚡ İşlem süresi: {duration:.2f}s"
|
| 384 |
|
| 385 |
except Exception as e:
|
| 386 |
-
|
| 387 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
-
def
|
| 390 |
-
"""
|
|
|
|
|
|
|
| 391 |
try:
|
| 392 |
-
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
except Exception as e:
|
| 395 |
-
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
|
| 398 |
-
# Gradio arayüzü -
|
| 399 |
demo = gr.ChatInterface(
|
| 400 |
-
fn=
|
| 401 |
-
title="
|
| 402 |
description="""
|
| 403 |
-
**CRANE AI
|
| 404 |
|
| 405 |
-
|
| 406 |
-
-
|
| 407 |
-
-
|
| 408 |
-
-
|
|
|
|
| 409 |
|
| 410 |
-
|
| 411 |
-
-
|
| 412 |
-
-
|
| 413 |
-
-
|
| 414 |
-
-
|
| 415 |
|
| 416 |
-
|
| 417 |
""",
|
| 418 |
-
theme=gr.themes.
|
| 419 |
examples=[
|
| 420 |
-
"
|
| 421 |
-
"
|
| 422 |
-
"
|
| 423 |
-
"
|
| 424 |
-
"
|
| 425 |
-
"Yapay zeka nedir?",
|
| 426 |
],
|
| 427 |
cache_examples=False,
|
| 428 |
-
concurrency_limit=2,
|
| 429 |
)
|
| 430 |
|
| 431 |
if __name__ == "__main__":
|
|
|
|
| 432 |
demo.launch(
|
| 433 |
share=False,
|
| 434 |
server_name="0.0.0.0",
|
| 435 |
server_port=7860,
|
| 436 |
-
show_error=True
|
|
|
|
| 437 |
)
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
CRANE AI - Debug Version
|
| 4 |
+
Hataları görmek için debug modlu
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 10 |
import logging
|
| 11 |
import os
|
| 12 |
import time
|
| 13 |
+
import traceback
|
| 14 |
|
| 15 |
# Logging
|
| 16 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 17 |
logger = logging.getLogger(__name__)
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Global değişkenler
|
| 20 |
model_cache = {}
|
| 21 |
+
error_count = 0
|
| 22 |
|
| 23 |
+
def simple_responses(message: str) -> str:
|
| 24 |
+
"""Basit yanıtlar - model olmadan"""
|
| 25 |
+
message_lower = message.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Selamlaşma
|
| 28 |
+
greetings = ["merhaba", "selam", "hi", "hello", "hey"]
|
| 29 |
+
if any(greeting in message_lower for greeting in greetings):
|
| 30 |
+
return "🏗️ Merhaba! Ben CRANE AI. ZeroGPU'da çalışıyorum!"
|
| 31 |
|
| 32 |
+
# Kod talebi
|
| 33 |
+
if "kod" in message_lower or "code" in message_lower:
|
| 34 |
+
if "hesap makinesi" in message_lower:
|
| 35 |
+
return """🔧 Python Hesap Makinesi:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
```python
|
| 38 |
def hesap_makinesi():
|
| 39 |
print("Basit Hesap Makinesi")
|
|
|
|
| 40 |
|
| 41 |
+
sayi1 = float(input("İlk sayı: "))
|
| 42 |
+
islem = input("İşlem (+, -, *, /): ")
|
| 43 |
+
sayi2 = float(input("İkinci sayı: "))
|
| 44 |
+
|
| 45 |
+
if islem == "+":
|
| 46 |
+
sonuc = sayi1 + sayi2
|
| 47 |
+
elif islem == "-":
|
| 48 |
+
sonuc = sayi1 - sayi2
|
| 49 |
+
elif islem == "*":
|
| 50 |
+
sonuc = sayi1 * sayi2
|
| 51 |
+
elif islem == "/":
|
| 52 |
+
sonuc = sayi1 / sayi2 if sayi2 != 0 else "Hata!"
|
| 53 |
+
|
| 54 |
+
print(f"Sonuç: {sonuc}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
|
|
|
| 56 |
hesap_makinesi()
|
| 57 |
```
|
| 58 |
|
| 59 |
+
⚡ CRANE AI kod üretimi!"""
|
| 60 |
+
else:
|
| 61 |
+
return "🔧 Ne tür kod yazmanızı istiyorsunuz? Örnek: 'Python hesap makinesi yaz'"
|
| 62 |
+
|
| 63 |
+
# AI soruları
|
| 64 |
+
if "ai" in message_lower or "yapay zeka" in message_lower:
|
| 65 |
+
return """🧠 CRANE AI Hakkında:
|
| 66 |
|
| 67 |
+
- 🏗️ Hibrit AI sistemi
|
| 68 |
+
- 🔥 ZeroGPU powered
|
| 69 |
+
- ⚡ Hızlı yanıtlar
|
| 70 |
+
- 🎯 Akıllı routing
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
4 farklı AI modülü birlikte çalışır!"""
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
# Varsayılan
|
| 75 |
+
return f"💬 '{message}' hakkında düşünüyorum... CRANE AI ile sohbet ediyoruz! 🚀"
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
@spaces.GPU(duration=60)
|
| 78 |
+
def process_with_gpu_debug(message: str) -> str:
|
| 79 |
+
"""Debug modlu GPU işleme"""
|
| 80 |
+
global error_count
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
try:
|
| 83 |
+
logger.info(f"🔥 GPU'da işleniyor: {message[:50]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
# GPU kontrolü
|
| 86 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 87 |
+
logger.info(f"🖥️ Cihaz: {device}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
start_time = time.time()
|
| 90 |
+
|
| 91 |
+
# Önce basit yanıtları dene
|
| 92 |
+
response = simple_responses(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
duration = time.time() - start_time
|
| 95 |
+
|
| 96 |
+
return f"{response}\n\n⚡ İşlem süresi: {duration:.2f}s (ZeroGPU, Cihaz: {device})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
except Exception as e:
|
| 99 |
+
error_count += 1
|
| 100 |
+
error_msg = str(e)
|
| 101 |
+
error_trace = traceback.format_exc()
|
| 102 |
+
|
| 103 |
+
logger.error(f"❌ GPU işlem hatası #{error_count}: {error_msg}")
|
| 104 |
+
logger.error(f"❌ Stack trace: {error_trace}")
|
| 105 |
+
|
| 106 |
+
return f"❌ Debug Hata #{error_count}: {error_msg}\n\nDetay: {error_trace[:200]}..."
|
| 107 |
|
| 108 |
+
def debug_chat_interface(message, history):
|
| 109 |
+
"""Debug chat interface"""
|
| 110 |
+
global error_count
|
| 111 |
+
|
| 112 |
try:
|
| 113 |
+
logger.info(f"📥 Gelen mesaj: {message}")
|
| 114 |
+
logger.info(f"📜 History uzunluğu: {len(history) if history else 0}")
|
| 115 |
+
|
| 116 |
+
# ZeroGPU kullanmadan basit test
|
| 117 |
+
if "test" in message.lower():
|
| 118 |
+
return f"✅ Test başarılı! Mesaj: '{message}' - Zaman: {time.time()}"
|
| 119 |
+
|
| 120 |
+
# GPU ile işle
|
| 121 |
+
result = process_with_gpu_debug(message)
|
| 122 |
+
logger.info(f"📤 Yanıt hazırlandı: {len(result)} karakter")
|
| 123 |
+
return result
|
| 124 |
+
|
| 125 |
except Exception as e:
|
| 126 |
+
error_count += 1
|
| 127 |
+
error_msg = str(e)
|
| 128 |
+
error_trace = traceback.format_exc()
|
| 129 |
+
|
| 130 |
+
logger.error(f"❌ Chat interface hatası #{error_count}: {error_msg}")
|
| 131 |
+
logger.error(f"❌ Stack trace: {error_trace}")
|
| 132 |
+
|
| 133 |
+
return f"""❌ Debug Hatası #{error_count}:
|
| 134 |
+
|
| 135 |
+
**Hata:** {error_msg}
|
| 136 |
+
|
| 137 |
+
**Stack Trace:**
|
| 138 |
+
{error_trace}
|
| 139 |
+
|
| 140 |
+
**Çözüm önerileri:**
|
| 141 |
+
1. 'test' yazarak basit testi deneyin
|
| 142 |
+
2. Kısa mesajlar gönderin
|
| 143 |
+
3. Birkaç saniye bekleyin
|
| 144 |
+
|
| 145 |
+
**Debug bilgisi:** {time.time()}"""
|
| 146 |
|
| 147 |
+
# Gradio arayüzü - Debug mode
|
| 148 |
demo = gr.ChatInterface(
|
| 149 |
+
fn=debug_chat_interface,
|
| 150 |
+
title="🐛 CRANE AI - Debug Mode",
|
| 151 |
description="""
|
| 152 |
+
**CRANE AI Debug Version** - Hataları görmek için
|
| 153 |
|
| 154 |
+
🐛 **Debug Features:**
|
| 155 |
+
- Detaylı hata mesajları
|
| 156 |
+
- Stack trace gösterimi
|
| 157 |
+
- Performance logging
|
| 158 |
+
- Step-by-step debugging
|
| 159 |
|
| 160 |
+
🔍 **Test komutları:**
|
| 161 |
+
- "test" - Basit bağlantı testi
|
| 162 |
+
- "merhaba" - Selamlaşma testi
|
| 163 |
+
- "kod yaz" - Kod üretimi testi
|
| 164 |
+
- "ai nedir" - AI bilgi testi
|
| 165 |
|
| 166 |
+
**Eğer sürekli hata alıyorsanız bu version size nedenini gösterecek!**
|
| 167 |
""",
|
| 168 |
+
theme=gr.themes.Base(),
|
| 169 |
examples=[
|
| 170 |
+
"test",
|
| 171 |
+
"merhaba",
|
| 172 |
+
"kod yaz",
|
| 173 |
+
"ai nedir",
|
| 174 |
+
"Python hesap makinesi yaz",
|
|
|
|
| 175 |
],
|
| 176 |
cache_examples=False,
|
|
|
|
| 177 |
)
|
| 178 |
|
| 179 |
if __name__ == "__main__":
|
| 180 |
+
print("🐛 CRANE AI Debug mode başlatılıyor...")
|
| 181 |
demo.launch(
|
| 182 |
share=False,
|
| 183 |
server_name="0.0.0.0",
|
| 184 |
server_port=7860,
|
| 185 |
+
show_error=True,
|
| 186 |
+
debug=True
|
| 187 |
)
|