Gradio ChatInterface uyumluluk hatası düzeltildi - type parametresi kaldırıldı
Browse files
app.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
CRANE AI - ZeroGPU Space Demo (Fixed)
|
| 4 |
HuggingFace ZeroGPU ile çalışır
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
import spaces
|
| 9 |
import torch
|
| 10 |
-
import asyncio
|
| 11 |
import logging
|
| 12 |
import os
|
| 13 |
-
from typing import Dict, Any
|
| 14 |
import time
|
| 15 |
|
| 16 |
# Logging
|
|
@@ -23,7 +21,6 @@ from modules.fast_module import FastModule
|
|
| 23 |
|
| 24 |
# Global değişkenler
|
| 25 |
model_cache = {}
|
| 26 |
-
router_cache = {}
|
| 27 |
|
| 28 |
@spaces.GPU(duration=120) # 2 dakika GPU
|
| 29 |
def initialize_gpu_model():
|
|
@@ -67,7 +64,7 @@ def initialize_gpu_model():
|
|
| 67 |
return None
|
| 68 |
|
| 69 |
@spaces.GPU(duration=60) # 1 dakika GPU
|
| 70 |
-
def process_with_gpu(message: str
|
| 71 |
"""GPU'da mesaj işler"""
|
| 72 |
try:
|
| 73 |
# Model yükle
|
|
@@ -178,30 +175,89 @@ print("İlk 10 Fibonacci sayısı:", fibonacci_list(10))
|
|
| 178 |
|
| 179 |
🚀 Hem recursive hem de optimize edilmiş versiyonlar!"""
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
else:
|
| 182 |
-
return f"""🔧 Kod modülü
|
| 183 |
|
| 184 |
İstediğiniz programlama dilinde kod yazabilirim:
|
| 185 |
-
- Python
|
| 186 |
-
- JavaScript
|
| 187 |
-
- HTML/CSS
|
| 188 |
-
- SQL
|
| 189 |
-
-
|
|
|
|
| 190 |
|
| 191 |
-
Örnek: "Python'da bir hesap makinesi yaz" veya "
|
| 192 |
|
| 193 |
⚡ ZeroGPU gücüyle hızlı kod üretimi!"""
|
| 194 |
|
| 195 |
# Genel AI soruları
|
| 196 |
-
ai_keywords = ["yapay zeka", "ai", "artificial intelligence", "machine learning", "deep learning"]
|
| 197 |
if any(keyword in message_lower for keyword in ai_keywords):
|
| 198 |
-
return """🧠 Yapay Zeka
|
| 199 |
|
| 200 |
**CRANE AI Sistemi:**
|
| 201 |
-
- 🏗️ Hibrit
|
| 202 |
-
- 🔥 ZeroGPU
|
| 203 |
-
- 🎯 Akıllı Router
|
| 204 |
-
- ⚡ Hızlı
|
| 205 |
|
| 206 |
**AI Modelleri:**
|
| 207 |
- **FastModule**: TinyLlama 1.1B (hızlı sorular)
|
|
@@ -214,23 +270,100 @@ print("İlk 10 Fibonacci sayısı:", fibonacci_list(10))
|
|
| 214 |
✅ Düşük kaynak kullanımı
|
| 215 |
✅ Yüksek performans
|
| 216 |
✅ Açık kaynak modeller
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
Yapay zeka geleceğin teknolojisi! 🚀"""
|
| 219 |
|
| 220 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
try:
|
| 222 |
# Modeli çağır
|
|
|
|
| 223 |
loop = asyncio.new_event_loop()
|
| 224 |
asyncio.set_event_loop(loop)
|
| 225 |
try:
|
| 226 |
-
prompt = f"Kullanıcı: {message}\
|
| 227 |
response = loop.run_until_complete(
|
| 228 |
-
module.generate_response(prompt, max_tokens=
|
| 229 |
)
|
| 230 |
|
| 231 |
# Prompt'u temizle
|
| 232 |
-
if "
|
| 233 |
-
response = response.split("
|
| 234 |
if "Kullanıcı:" in response:
|
| 235 |
response = response.split("Kullanıcı:")[0].strip()
|
| 236 |
|
|
@@ -246,52 +379,53 @@ Yapay zeka geleceğin teknolojisi! 🚀"""
|
|
| 246 |
|
| 247 |
except Exception as e:
|
| 248 |
logger.error(f"Model çalıştırma hatası: {e}")
|
| 249 |
-
|
|
|
|
| 250 |
|
| 251 |
except Exception as e:
|
| 252 |
logger.error(f"ZeroGPU işlem hatası: {e}")
|
| 253 |
return f"❌ Geçici bir hata oluştu. Lütfen tekrar deneyin."
|
| 254 |
|
| 255 |
def chat_interface(message, history):
|
| 256 |
-
"""Gradio chat interface"""
|
| 257 |
try:
|
| 258 |
-
|
|
|
|
| 259 |
except Exception as e:
|
| 260 |
logger.error(f"Chat interface hatası: {e}")
|
| 261 |
return f"⚠️ Sistem şu anda meşgul. Lütfen birkaç saniye sonra tekrar deneyin."
|
| 262 |
|
| 263 |
-
# Gradio arayüzü
|
| 264 |
demo = gr.ChatInterface(
|
| 265 |
fn=chat_interface,
|
| 266 |
-
type="messages",
|
| 267 |
title="🏗️ CRANE AI - ZeroGPU Powered",
|
| 268 |
description="""
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
""",
|
| 284 |
theme=gr.themes.Soft(),
|
| 285 |
examples=[
|
| 286 |
"Merhaba! CRANE AI nasıl çalışır?",
|
| 287 |
"Python'da bir hesap makinesi yaz",
|
| 288 |
"Fibonacci dizisi algoritması",
|
| 289 |
-
"
|
| 290 |
-
"Web development hakkında bilgi ver",
|
| 291 |
"React vs Vue karşılaştırması",
|
|
|
|
| 292 |
],
|
| 293 |
-
cache_examples=False,
|
| 294 |
-
concurrency_limit=2,
|
| 295 |
)
|
| 296 |
|
| 297 |
if __name__ == "__main__":
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
CRANE AI - ZeroGPU Space Demo (Gradio Fixed)
|
| 4 |
HuggingFace ZeroGPU ile çalışır
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
| 8 |
import spaces
|
| 9 |
import torch
|
|
|
|
| 10 |
import logging
|
| 11 |
import os
|
|
|
|
| 12 |
import time
|
| 13 |
|
| 14 |
# Logging
|
|
|
|
| 21 |
|
| 22 |
# Global değişkenler
|
| 23 |
model_cache = {}
|
|
|
|
| 24 |
|
| 25 |
@spaces.GPU(duration=120) # 2 dakika GPU
|
| 26 |
def initialize_gpu_model():
|
|
|
|
| 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
|
|
|
|
| 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 |
# Genel AI soruları
|
| 252 |
+
ai_keywords = ["yapay zeka", "ai", "artificial intelligence", "machine learning", "deep learning", "crane ai"]
|
| 253 |
if any(keyword in message_lower for keyword in ai_keywords):
|
| 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)
|
|
|
|
| 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 |
+
# Teknoloji soruları
|
| 284 |
+
tech_keywords = ["react", "vue", "javascript", "web development", "programming"]
|
| 285 |
+
if any(keyword in message_lower for keyword in tech_keywords):
|
| 286 |
+
if "react" in message_lower and "vue" in message_lower:
|
| 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 |
+
# Varsayılan yanıt - Model kullanarak
|
| 353 |
try:
|
| 354 |
# Modeli çağır
|
| 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 |
|
|
|
|
| 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 |
logger.error(f"ZeroGPU işlem hatası: {e}")
|
| 387 |
return f"❌ Geçici bir hata oluştu. Lütfen tekrar deneyin."
|
| 388 |
|
| 389 |
def chat_interface(message, history):
|
| 390 |
+
"""Gradio chat interface - history uyumlu"""
|
| 391 |
try:
|
| 392 |
+
# History'yi göz ardı et, sadece message'ı işle
|
| 393 |
+
return process_with_gpu(message)
|
| 394 |
except Exception as e:
|
| 395 |
logger.error(f"Chat interface hatası: {e}")
|
| 396 |
return f"⚠️ Sistem şu anda meşgul. Lütfen birkaç saniye sonra tekrar deneyin."
|
| 397 |
|
| 398 |
+
# Gradio arayüzü - Uyumlu parametreler
|
| 399 |
demo = gr.ChatInterface(
|
| 400 |
fn=chat_interface,
|
|
|
|
| 401 |
title="🏗️ CRANE AI - ZeroGPU Powered",
|
| 402 |
description="""
|
| 403 |
+
**CRANE AI Hibrit Yapay Zeka Sistemi** - HuggingFace ZeroGPU ile güçlendirilmiş
|
| 404 |
+
|
| 405 |
+
🔥 **ZeroGPU Features:**
|
| 406 |
+
- Ücretsiz GPU erişimi (NVIDIA A100/T4)
|
| 407 |
+
- Hızlı model yükleme ve çalıştırma
|
| 408 |
+
- Optimize edilmiş performans
|
| 409 |
+
|
| 410 |
+
🧠 **Desteklenen Görevler:**
|
| 411 |
+
- 💬 Genel sohbet ve sorular
|
| 412 |
+
- 🔧 Kod yazma (Python, JS, HTML...)
|
| 413 |
+
- 🤔 Problem çözme ve analiz
|
| 414 |
+
- ⚡ Hızlı bilgi sorguları
|
| 415 |
+
|
| 416 |
+
🏗️ **Hibrit Sistem:** Küçük ama güçlü modeller birlikte çalışır
|
| 417 |
""",
|
| 418 |
theme=gr.themes.Soft(),
|
| 419 |
examples=[
|
| 420 |
"Merhaba! CRANE AI nasıl çalışır?",
|
| 421 |
"Python'da bir hesap makinesi yaz",
|
| 422 |
"Fibonacci dizisi algoritması",
|
| 423 |
+
"HTML ile web sayfası oluştur",
|
|
|
|
| 424 |
"React vs Vue karşılaştırması",
|
| 425 |
+
"Yapay zeka nedir?",
|
| 426 |
],
|
| 427 |
+
cache_examples=False,
|
| 428 |
+
concurrency_limit=2,
|
| 429 |
)
|
| 430 |
|
| 431 |
if __name__ == "__main__":
|