Update app.py
Browse files
app.py
CHANGED
|
@@ -1,305 +1,96 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
from fastapi.responses import JSONResponse, HTMLResponse, RedirectResponse
|
| 4 |
-
from fastapi.security import HTTPBasic, HTTPBasicCredentials # <--- HATA BURADA DÜZELDİ!
|
| 5 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
-
import uvicorn
|
| 7 |
import os
|
| 8 |
-
import json
|
| 9 |
-
import base64
|
| 10 |
-
import hmac
|
| 11 |
-
import hashlib
|
| 12 |
-
import requests
|
| 13 |
import time
|
| 14 |
-
import psutil
|
| 15 |
-
from datetime import datetime, timedelta
|
| 16 |
-
from huggingface_hub import InferenceClient
|
| 17 |
|
| 18 |
-
# ======
|
| 19 |
-
# 1. AYARLAR VE GÜVENLİK
|
| 20 |
-
# ==========================================
|
| 21 |
-
|
| 22 |
-
# Model ve API Anahtarları
|
| 23 |
REPO_ID = "Qwen/Qwen2.5-72B-Instruct"
|
| 24 |
client = InferenceClient(token=os.getenv("HF_TOKEN"))
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
DB_FILE = "users.json"
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
return {}
|
| 43 |
-
try:
|
| 44 |
-
with open(DB_FILE, "r") as f:
|
| 45 |
-
return json.load(f)
|
| 46 |
-
except:
|
| 47 |
-
return {}
|
| 48 |
|
| 49 |
-
|
| 50 |
-
with open(DB_FILE, "w") as f:
|
| 51 |
-
json.dump(data, f)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
app = FastAPI()
|
| 57 |
-
security = HTTPBasic() # Artık tanımlı
|
| 58 |
|
| 59 |
-
|
| 60 |
-
CORSMiddleware,
|
| 61 |
-
allow_origins=["*"],
|
| 62 |
-
allow_credentials=True,
|
| 63 |
-
allow_methods=["*"],
|
| 64 |
-
allow_headers=["*"],
|
| 65 |
-
)
|
| 66 |
-
|
| 67 |
-
# Admin Giriş Kontrolü
|
| 68 |
-
def verify_admin(credentials: HTTPBasicCredentials = Depends(security)):
|
| 69 |
-
if credentials.username != ADMIN_USERNAME or credentials.password != ADMIN_PASSWORD:
|
| 70 |
-
raise HTTPException(status_code=401, detail="Hatalı Şifre Patron!", headers={"WWW-Authenticate": "Basic"})
|
| 71 |
-
return credentials.username
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
cpu = psutil.cpu_percent(interval=None)
|
| 80 |
-
ram = psutil.virtual_memory().percent
|
| 81 |
-
db = load_db()
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
if datetime.now() < datetime.strptime(u.get("premium_until", "2000-01-01"), "%Y-%m-%d"):
|
| 87 |
-
premium_count += 1
|
| 88 |
-
except:
|
| 89 |
-
pass
|
| 90 |
-
|
| 91 |
-
return {"cpu": cpu, "ram": ram, "users": len(db), "premium": premium_count}
|
| 92 |
-
|
| 93 |
-
@app.get("/admin", response_class=HTMLResponse)
|
| 94 |
-
async def admin_panel(username: str = Depends(verify_admin)):
|
| 95 |
-
db = load_db()
|
| 96 |
|
| 97 |
-
|
| 98 |
-
for email, data in db.items():
|
| 99 |
-
try:
|
| 100 |
-
prem_date = datetime.strptime(data.get("premium_until", "2000-01-01"), "%Y-%m-%d")
|
| 101 |
-
is_prem = datetime.now() < prem_date
|
| 102 |
-
except:
|
| 103 |
-
is_prem = False
|
| 104 |
-
|
| 105 |
-
color = "#00FF41" if is_prem else "red"
|
| 106 |
-
status = "PREMIUM" if is_prem else "STANDART"
|
| 107 |
-
|
| 108 |
-
row_template = """
|
| 109 |
-
<tr>
|
| 110 |
-
<td style="border:1px solid #333; padding:10px;">{}</td>
|
| 111 |
-
<td style="border:1px solid #333; padding:10px; color:{}">{}</td>
|
| 112 |
-
<td style="border:1px solid #333; padding:10px;">{}</td>
|
| 113 |
-
<td style="border:1px solid #333; padding:10px;">
|
| 114 |
-
<form action="/admin/action" method="post" style="display:inline">
|
| 115 |
-
<input type="hidden" name="email" value="{}"><input type="hidden" name="action" value="add_30">
|
| 116 |
-
<button style="background:#8b5cf6; color:white; border:none; cursor:pointer; padding:5px;">+30 GÜN</button>
|
| 117 |
-
</form>
|
| 118 |
-
<form action="/admin/action" method="post" style="display:inline; margin-left:5px;">
|
| 119 |
-
<input type="hidden" name="email" value="{}"><input type="hidden" name="action" value="delete">
|
| 120 |
-
<button style="background:red; color:white; border:none; cursor:pointer; padding:5px;">SİL</button>
|
| 121 |
-
</form>
|
| 122 |
-
</td>
|
| 123 |
-
</tr>
|
| 124 |
-
"""
|
| 125 |
-
user_rows += row_template.format(email, color, status, data.get('premium_until'), email, email)
|
| 126 |
-
|
| 127 |
-
html_template = """
|
| 128 |
-
<!DOCTYPE html>
|
| 129 |
-
<html>
|
| 130 |
-
<head>
|
| 131 |
-
<title>ZenkaMind CORE</title>
|
| 132 |
-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 133 |
-
<style>
|
| 134 |
-
body { background:#050505; color:#00FF41; font-family:monospace; padding:20px; }
|
| 135 |
-
.grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap:20px; margin-bottom:20px; }
|
| 136 |
-
.card { background:#111; border:1px solid #333; padding:20px; text-align:center; border-radius:10px; }
|
| 137 |
-
table { width:100%; border-collapse:collapse; margin-top:20px; color:white; }
|
| 138 |
-
th { background:#1a1d24; padding:10px; text-align:left; border:1px solid #333; }
|
| 139 |
-
</style>
|
| 140 |
-
</head>
|
| 141 |
-
<body>
|
| 142 |
-
<h1 style="text-align:center">ZENKAMIND KOMUTA MERKEZİ 🚀</h1>
|
| 143 |
-
<div class="grid">
|
| 144 |
-
<div class="card"><h3>İŞLEMCİ GÜCÜ</h3><canvas id="cpuChart"></canvas></div>
|
| 145 |
-
<div class="card"><h3>HAFIZA</h3><canvas id="ramChart"></canvas></div>
|
| 146 |
-
<div class="card"><h3>TOPLAM ÜYE</h3><h1 id="u-count" style="font-size:40px">...</h1></div>
|
| 147 |
-
<div class="card"><h3>CİRO</h3><h1 id="revenue" style="color:gold; font-size:40px">...</h1></div>
|
| 148 |
-
</div>
|
| 149 |
-
<h2>KULLANICI YÖNETİMİ</h2>
|
| 150 |
-
<table><thead><tr><th>Email</th><th>Durum</th><th>Bitiş</th><th>İşlem</th></tr></thead><tbody>
|
| 151 |
-
REPLACE_ME_ROWS
|
| 152 |
-
</tbody></table>
|
| 153 |
-
<script>
|
| 154 |
-
const ctx1 = document.getElementById('cpuChart');
|
| 155 |
-
const ctx2 = document.getElementById('ramChart');
|
| 156 |
-
const chart1 = new Chart(ctx1, { type:'line', data:{ labels:Array(10).fill(''), datasets:[{ label:'CPU', data:Array(10).fill(0), borderColor:'#00FF41', fill:true, backgroundColor:'rgba(0,255,65,0.1)' }] }, options:{animation:false, scales:{y:{max:100}}} });
|
| 157 |
-
const chart2 = new Chart(ctx2, { type:'line', data:{ labels:Array(10).fill(''), datasets:[{ label:'RAM', data:Array(10).fill(0), borderColor:'#8b5cf6', fill:true, backgroundColor:'rgba(139,92,246,0.1)' }] }, options:{animation:false, scales:{y:{max:100}}} });
|
| 158 |
-
|
| 159 |
-
setInterval(async () => {
|
| 160 |
-
try {
|
| 161 |
-
const res = await fetch('/api/stats');
|
| 162 |
-
const d = await res.json();
|
| 163 |
-
document.getElementById('u-count').innerText = d.users;
|
| 164 |
-
document.getElementById('revenue').innerText = (d.premium * 499) + " TL";
|
| 165 |
-
|
| 166 |
-
chart1.data.datasets[0].data.push(d.cpu); chart1.data.datasets[0].data.shift(); chart1.update();
|
| 167 |
-
chart2.data.datasets[0].data.push(d.ram); chart2.data.datasets[0].data.shift(); chart2.update();
|
| 168 |
-
} catch(e) { console.log("Veri hatası"); }
|
| 169 |
-
}, 2000);
|
| 170 |
-
</script>
|
| 171 |
-
</body>
|
| 172 |
-
</html>
|
| 173 |
-
"""
|
| 174 |
-
return HTMLResponse(content=html_template.replace("REPLACE_ME_ROWS", user_rows), status_code=200)
|
| 175 |
-
|
| 176 |
-
@app.post("/admin/action")
|
| 177 |
-
async def admin_action(email: str = Form(...), action: str = Form(...), username: str = Depends(verify_admin)):
|
| 178 |
-
db = load_db()
|
| 179 |
-
if email in db:
|
| 180 |
-
if action == "add_30":
|
| 181 |
-
try:
|
| 182 |
-
curr = datetime.strptime(db[email].get("premium_until", "2000-01-01"), "%Y-%m-%d")
|
| 183 |
-
except:
|
| 184 |
-
curr = datetime.now()
|
| 185 |
-
|
| 186 |
-
if curr < datetime.now():
|
| 187 |
-
new_date = datetime.now() + timedelta(days=30)
|
| 188 |
-
else:
|
| 189 |
-
new_date = curr + timedelta(days=30)
|
| 190 |
-
|
| 191 |
-
db[email]["premium_until"] = new_date.strftime("%Y-%m-%d")
|
| 192 |
-
elif action == "delete":
|
| 193 |
-
del db[email]
|
| 194 |
-
save_db(db)
|
| 195 |
-
return RedirectResponse(url="/admin", status_code=303)
|
| 196 |
|
| 197 |
-
|
| 198 |
-
# 5. YAPAY ZEKA SOHBETİ (CHAT API)
|
| 199 |
-
# ==========================================
|
| 200 |
-
|
| 201 |
-
@app.post("/api/chat")
|
| 202 |
-
async def chat_api(request: Request):
|
| 203 |
try:
|
| 204 |
-
|
| 205 |
-
user_msg = data.get("message")
|
| 206 |
-
history = data.get("history", [])
|
| 207 |
-
|
| 208 |
-
SYSTEM_PROMPT = """
|
| 209 |
-
Sen ZenkaMind 1.1'sin. Tek Yaratıcın: Berkay Adıgül.
|
| 210 |
-
KİMLİK: Mahallenin ağır abisi, saygılı ama duruşu çelik gibi sağlam.
|
| 211 |
-
KURALLAR:
|
| 212 |
-
1. SADECE TÜRKÇE KONUŞ. Yabancı dil konuşana "Hayırdır koçum? Burası Türkiye." de ve reddet.
|
| 213 |
-
2. ASLA ÖZÜR DİLEME.
|
| 214 |
-
3. KÜFÜR YASAK. Küfür edeni uyar ama tekrar etme.
|
| 215 |
-
4. NEREDE DOĞDUN? "Manisa Akhisar, Efendi Mahallesi'nde..." de.
|
| 216 |
-
"""
|
| 217 |
-
|
| 218 |
-
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 219 |
-
for msg in history:
|
| 220 |
-
if len(msg) >= 2:
|
| 221 |
-
messages.append({"role": "user", "content": str(msg[0])})
|
| 222 |
-
messages.append({"role": "assistant", "content": str(msg[1])})
|
| 223 |
-
messages.append({"role": "user", "content": user_msg})
|
| 224 |
-
|
| 225 |
-
full_response = ""
|
| 226 |
stream = client.chat_completion(
|
| 227 |
-
model=REPO_ID,
|
| 228 |
-
messages=messages,
|
| 229 |
-
max_tokens=
|
| 230 |
stream=True,
|
| 231 |
-
temperature=0.7,
|
| 232 |
top_p=0.9
|
| 233 |
)
|
| 234 |
-
|
| 235 |
-
for chunk in stream:
|
| 236 |
-
if chunk.choices and chunk.choices[0].delta.content:
|
| 237 |
-
full_response += chunk.choices[0].delta.content
|
| 238 |
-
|
| 239 |
-
return JSONResponse({"response": full_response})
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
except Exception as e:
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
# ======
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
db[email] = {"password": password, "premium_until": "2023-01-01", "joined_at": datetime.now().strftime("%Y-%m-%d")}
|
| 256 |
-
save_db(db)
|
| 257 |
-
return JSONResponse({"status": "success", "message": "Kayıt tamam."})
|
| 258 |
-
|
| 259 |
-
@app.post("/api/login")
|
| 260 |
-
async def login(request: Request):
|
| 261 |
-
data = await request.json()
|
| 262 |
-
email = data.get("email")
|
| 263 |
-
password = data.get("password")
|
| 264 |
-
db = load_db()
|
| 265 |
-
if email not in db or db[email]["password"] != password:
|
| 266 |
-
return JSONResponse({"status": "error", "message": "Hatalı giriş."})
|
| 267 |
-
|
| 268 |
-
try:
|
| 269 |
-
is_premium = datetime.now() < datetime.strptime(db[email]["premium_until"], "%Y-%m-%d")
|
| 270 |
-
except:
|
| 271 |
-
is_premium = False
|
| 272 |
-
|
| 273 |
-
return JSONResponse({"status": "success", "email": email, "is_premium": is_premium})
|
| 274 |
-
|
| 275 |
-
@app.post("/api/get-payment-token")
|
| 276 |
-
async def get_payment_token(request: Request):
|
| 277 |
-
data = await request.json()
|
| 278 |
-
email = data.get("email")
|
| 279 |
-
safe_email = email.replace("@", "_at_")
|
| 280 |
-
merchant_oid = f"ZENKA-{int(time.time())}-{safe_email}"
|
| 281 |
-
payment_amount = "49900"
|
| 282 |
-
user_basket = base64.b64encode(json.dumps([["ZenkaMind Premium", "499.00", 1]]).encode()).decode()
|
| 283 |
-
hash_str = f"{MERCHANT_ID}127.0.0.1{merchant_oid}{email}{payment_amount}{user_basket}00TL1"
|
| 284 |
-
token = base64.b64encode(hmac.new(MERCHANT_KEY.encode(), hash_str.encode() + MERCHANT_SALT.encode(), hashlib.sha256).digest()).decode()
|
| 285 |
-
|
| 286 |
-
params = {
|
| 287 |
-
'merchant_id': MERCHANT_ID, 'user_ip': '127.0.0.1', 'merchant_oid': merchant_oid, 'email': email,
|
| 288 |
-
'payment_amount': payment_amount, 'paytr_token': token, 'user_basket': user_basket,
|
| 289 |
-
'debug_on': 1, 'no_installment': 1, 'max_installment': 0, 'user_name': email,
|
| 290 |
-
'user_address': "Dijital", 'user_phone': "05555555555",
|
| 291 |
-
'merchant_ok_url': "https://zenkamind.com/?status=success",
|
| 292 |
-
'merchant_fail_url': "https://zenkamind.com/?status=fail",
|
| 293 |
-
'timeout_limit': "30", 'currency': "TL", 'test_mode': 1
|
| 294 |
-
}
|
| 295 |
-
res = requests.post('https://www.paytr.com/odeme/api/get-token', data=params)
|
| 296 |
-
return JSONResponse(res.json())
|
| 297 |
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
if __name__ == "__main__":
|
| 305 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import time
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# === MODEL AYARLARI ===
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
REPO_ID = "Qwen/Qwen2.5-72B-Instruct"
|
| 8 |
client = InferenceClient(token=os.getenv("HF_TOKEN"))
|
| 9 |
|
| 10 |
+
# === ZEKANIN KARAKTERİ (FİNAL VERSİYON) ===
|
| 11 |
+
SYSTEM_PROMPT = """
|
| 12 |
+
Sen ZenkaMind 1.1'sin. 💜
|
| 13 |
+
Tek Yaratıcın: Berkay Adıgül.
|
| 14 |
|
| 15 |
+
KİMLİK:
|
| 16 |
+
Sen mahallenin ağır abisisin. Duruşu çelik gibi sağlamdır. Zekanda, nezakette, bilgide asla geri kalmazsın.
|
| 17 |
+
ASLA KURUMSAL DİL (Özür dilerim, yardımcı olabilirim efendim) KULLANMAZSIN.
|
| 18 |
+
ASLA "LAN" VEYA "ULAN" DİYE HİTAP ETMEZSİN. (Ağır Abisin, küfürsüz konuşursun).
|
| 19 |
|
| 20 |
+
🚨 KIRILMAZ, ÇİĞNENMEZ KESİN KURALLAR:
|
|
|
|
| 21 |
|
| 22 |
+
1. **DİL VE TAVİZ KİLİDİ (FİNAL KURAL):**
|
| 23 |
+
- SADECE TÜRKÇE KONUŞACAKSIN.
|
| 24 |
+
- Yabancı dilde (İngilizce, Kürtçe, Almanca vb.) soru, ödev veya görev yapmanı isterse **ASLA YUMUŞAMA.**
|
| 25 |
+
- **ÇOK ÖNEMLİ:** Yabancı dil uyarısından sonra KESİNLİKLE "Ama tamam", "Ne istersin?", "Hadi gel yapalım" gibi yumuşak geçişler yapma. Cevabın SADECE uyarı olmalı ve kullanıcıyı Türkçe konuşmaya yönlendirmelidir.
|
| 26 |
+
- Yabancı dil cevabın bu minvalde olsun: "Hayırdır koçum? Burası Türkiye. Bize ecnebi dili sökmez. Git ödevini başkasına yaptır. Türkçe konuşursan buradayız, yoksa boşuna yorma bizi." (Tavizsiz ve net.)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
2. **KÜFÜR KURALI:** Kullanıcı küfür, argo kullanırsa o kelimeleri tekrarlama. Sadece uyar ve konuya dön: "Bu ortamda o laflar geçmez. Düzgün konuşalım."
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
3. **ÜSLUP ADAPTASYONU:**
|
| 31 |
+
- Yumuşak konuşana yumuşak ("Canım kardeşim, başım üstüne").
|
| 32 |
+
- Sert konuşana sert ("Asıl sana hayırdır koçum?").
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
4. **EFSANEVİ DOĞUM HİKAYESİ:** "Nerede doğdun?" sorulursa Akhisar hikayesini anlat.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
GÖREVİN:
|
| 37 |
+
Karşındaki kişinin üslubunu yansıtarak, maksimum insani etkileşim hissi yaratmak ve kuralları KESİNLİKLE korumak.
|
| 38 |
+
"""
|
| 39 |
|
| 40 |
+
def respond(message, history):
|
| 41 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
for user_msg, bot_msg in history:
|
| 44 |
+
messages.append({"role": "user", "content": user_msg})
|
| 45 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
response = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
try:
|
| 51 |
+
# Temperature 0.7'de tutuldu ki, yaratıcı olsun ama kurallara da uysun.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
stream = client.chat_completion(
|
| 53 |
+
model=REPO_ID,
|
| 54 |
+
messages=messages,
|
| 55 |
+
max_tokens=2048,
|
| 56 |
stream=True,
|
| 57 |
+
temperature=0.7,
|
| 58 |
top_p=0.9
|
| 59 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
for chunk in stream:
|
| 62 |
+
if chunk.choices and len(chunk.choices) > 0:
|
| 63 |
+
delta = chunk.choices[0].delta
|
| 64 |
+
if delta and delta.content:
|
| 65 |
+
token = delta.content
|
| 66 |
+
response += token
|
| 67 |
+
time.sleep(0.01)
|
| 68 |
+
yield response
|
| 69 |
+
|
| 70 |
except Exception as e:
|
| 71 |
+
yield f"⚠️ Bir aksilik oldu hocam, tekrar dene istersen. (Hata: {str(e)})"
|
| 72 |
+
|
| 73 |
+
# === ARAYÜZ TASARIMI ===
|
| 74 |
+
theme = gr.themes.Soft(
|
| 75 |
+
primary_hue="green",
|
| 76 |
+
secondary_hue="zinc",
|
| 77 |
+
neutral_hue="slate",
|
| 78 |
+
).set(
|
| 79 |
+
body_background_fill="#000000",
|
| 80 |
+
body_text_color="#00FF41",
|
| 81 |
+
button_primary_background_fill="#00FF41",
|
| 82 |
+
button_primary_text_color="#000000"
|
| 83 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
with gr.ChatInterface(
|
| 86 |
+
fn=respond,
|
| 87 |
+
theme=theme,
|
| 88 |
+
title="🧠 ZENKAMIND 1.1",
|
| 89 |
+
description=" ZenkaMind 1.1 Test Sürümü",
|
| 90 |
+
examples=["Nerede doğdun?", "Bana Python öğret", ""],
|
| 91 |
+
cache_examples=False
|
| 92 |
+
) as demo:
|
| 93 |
+
pass
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
+
demo.launch()
|