BehradB2 commited on
Commit
edd7955
·
verified ·
1 Parent(s): dd10f6e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +48 -33
main.py CHANGED
@@ -7,16 +7,22 @@ import itertools
7
  import datetime
8
 
9
  # ==========================================
10
- # ۱. مدیریت کلیدها و آمار (Behrad AI Core)
11
  # ==========================================
12
- # لیست کلیدهای خود را اینجا قرار دهید
13
  API_KEYS = [
14
- "AIzaSyCaUj_SFJ9IY_THJ8nci8UnIotfCklO_Yc",
15
- "AIzaSyD-BeqfkCjjFtHPsp9ckUxkQIz5M2QBzMg",
16
- "AIzaSyCYfXgkmuOgPGNW5Nw3uL_gkCimNbzLt-g"
17
  ]
18
 
 
19
  key_cycle = itertools.cycle(API_KEYS)
 
 
 
 
 
20
  stats = {
21
  "total_requests": 0,
22
  "success_count": 0,
@@ -24,10 +30,9 @@ stats = {
24
  "start_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
25
  }
26
 
27
- MY_SECRET_PASS = "Behrad_King_2026" # رمز اختصاصی شما
28
-
29
- app = FastAPI(title="Behrad AI Core V3.1")
30
 
 
31
  app.add_middleware(
32
  CORSMiddleware,
33
  allow_origins=["*"],
@@ -39,7 +44,7 @@ class AIRequest(BaseModel):
39
  prompt: str
40
 
41
  # ==========================================
42
- # ۲. بخش عمومی (Apple Style UI)
43
  # ==========================================
44
  @app.get("/", response_class=HTMLResponse)
45
  async def public_ui():
@@ -50,24 +55,24 @@ async def public_ui():
50
  <meta charset="UTF-8">
51
  <style>
52
  body { background: #f5f5f7; font-family: -apple-system, sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
53
- .glass { background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(20px); border-radius: 40px; padding: 60px; box-shadow: 0 20px 50px rgba(0,0,0,0.05); text-align: center; border: 1px solid rgba(255,255,255,0.3); max-width: 500px; }
54
- h1 { font-size: 52px; font-weight: 700; color: #1d1d1f; letter-spacing: -2px; margin-bottom: 10px; }
55
- p { color: #86868b; font-size: 20px; line-height: 1.5; }
56
- .status { display: inline-block; margin-top: 30px; padding: 8px 20px; background: #0071e3; color: white; border-radius: 20px; font-size: 14px; }
57
  </style>
58
  </head>
59
  <body>
60
- <div class="glass">
61
  <h1>Behrad AI</h1>
62
- <p>قدرت گرفته از جدیدترین نسخه Gemini Flash. سرعت و دقت در پروژه‌های هوشمند شما.</p>
63
- <div class="status">سیستم آنلاین است</div>
64
  </div>
65
  </body>
66
  </html>
67
  """
68
 
69
  # ==========================================
70
- # ۳. پنل مدیریت (Engineering Dashboard)
71
  # ==========================================
72
  @app.get("/admin", response_class=HTMLResponse)
73
  async def admin_ui():
@@ -75,48 +80,57 @@ async def admin_ui():
75
  <!DOCTYPE html>
76
  <html>
77
  <head>
78
- <title>Admin Panel | Behrad AI</title>
79
  <style>
80
- body {{ background: #0a0a0a; color: #4af626; font-family: 'Courier New', monospace; padding: 30px; }}
81
- .terminal {{ border: 1px solid #4af626; padding: 25px; border-radius: 10px; }}
82
- .grid {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin: 30px 0; }}
83
  .stat-box {{ border: 1px dashed #4af626; padding: 20px; text-align: center; }}
84
- .model-tag {{ color: #fff; background: #d4413d; padding: 2px 8px; border-radius: 4px; font-size: 12px; }}
 
85
  </style>
86
  </head>
87
  <body>
88
- <div class="terminal">
89
- <h2>> BEHRAD_AI_CORE_V3.1 <span class="model-tag">GEMINI-FLASH-LATEST</span></h2>
90
- <p>SERVER_STATUS: ACTIVE | START_TIME: {stats['start_time']}</p>
91
- <div class="grid">
92
  <div class="stat-box">REQUESTS<div>{stats['total_requests']}</div></div>
93
  <div class="stat-box">SUCCESS<div>{stats['success_count']}</div></div>
94
  <div class="stat-box">ERRORS<div>{stats['error_count']}</div></div>
95
  <div class="stat-box">KEYS<div>{len(API_KEYS)}</div></div>
96
  </div>
97
- <div style="font-size: 12px; opacity: 0.6;">> Listening on /ask for secure tokens...</div>
 
 
 
 
98
  </div>
99
  </body>
100
  </html>
101
  """
102
 
103
  # ==========================================
104
- # ۴. هسته پردازشی با مدل جدید
105
  # ==========================================
106
  @app.post("/ask")
107
  async def ask_ai(request: AIRequest, x_api_token: str = Header(...)):
 
108
  if x_api_token != MY_SECRET_PASS:
109
  stats["error_count"] += 1
110
- raise HTTPException(status_code=403, detail="Access Denied")
111
 
112
  stats["total_requests"] += 1
 
 
113
  current_key = next(key_cycle)
114
 
115
  try:
 
116
  genai.configure(api_key=current_key)
117
 
118
- # --- جایگزینی مدل درخواستی شما ---
119
- model = genai.GenerativeModel('gemini-1.5-flash-latest')
120
 
121
  response = model.generate_content(request.prompt)
122
 
@@ -124,12 +138,13 @@ async def ask_ai(request: AIRequest, x_api_token: str = Header(...)):
124
  return {
125
  "status": "success",
126
  "answer": response.text,
127
- "engine": "gemini-flash-latest"
128
  }
129
 
130
  except Exception as e:
131
  stats["error_count"] += 1
132
  return {
133
  "status": "error",
134
- "message": str(e)
 
135
  }
 
7
  import datetime
8
 
9
  # ==========================================
10
+ # ۱. پیکربندی سیستم چرخش کلید (Multi-Key)
11
  # ==========================================
12
+ # کلیدهای واقعی خودت را اینجا داخل لیست بگذار
13
  API_KEYS = [
14
+ "AIzaSyB2_RkZdEaVqiq7Qu3oMB1ya86cJHe0lLM",
15
+ "AIzaSyD-7i8Y2iAiqNXJY1jklcGZNk6GdUsymOE",
16
+ "AIzaSyBBRlkT-86gGwY9UvrYMSBmIetZK5Uu9xI"
17
  ]
18
 
19
+ # ایجاد چرخه برای استفاده نوبتی از کلیدها
20
  key_cycle = itertools.cycle(API_KEYS)
21
+
22
+ # رمز عبور اختصاصی بهراد
23
+ MY_SECRET_PASS = "Behrad_King_2026"
24
+
25
+ # آمارهای زنده برای پنل مدیریت
26
  stats = {
27
  "total_requests": 0,
28
  "success_count": 0,
 
30
  "start_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
31
  }
32
 
33
+ app = FastAPI(title="Behrad AI Core V3.1 - Flash Edition")
 
 
34
 
35
+ # آزاد کردن دسترسی برای تمام پروژه‌های تو (CORS)
36
  app.add_middleware(
37
  CORSMiddleware,
38
  allow_origins=["*"],
 
44
  prompt: str
45
 
46
  # ==========================================
47
+ # ۲. ظاهر عمومی (Apple Luxury Style) - آدرس /
48
  # ==========================================
49
  @app.get("/", response_class=HTMLResponse)
50
  async def public_ui():
 
55
  <meta charset="UTF-8">
56
  <style>
57
  body { background: #f5f5f7; font-family: -apple-system, sans-serif; display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
58
+ .glass-card { background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(25px); border-radius: 35px; padding: 60px; box-shadow: 0 30px 60px rgba(0,0,0,0.06); text-align: center; border: 1px solid rgba(255,255,255,0.4); max-width: 450px; }
59
+ h1 { font-size: 50px; font-weight: 700; color: #1d1d1f; letter-spacing: -2px; margin-bottom: 15px; }
60
+ p { color: #86868b; font-size: 20px; font-weight: 400; line-height: 1.6; }
61
+ .btn { display: inline-block; margin-top: 40px; padding: 12px 30px; background: #0071e3; color: white; border-radius: 25px; text-decoration: none; font-size: 15px; font-weight: 500; }
62
  </style>
63
  </head>
64
  <body>
65
+ <div class="glass-card">
66
  <h1>Behrad AI</h1>
67
+ <p>قدرت‌گرفته از سریع‌ترین هوش مصنوعی جهان. آینده پروژه‌های هوشمند بهراد در دستان شماست.</p>
68
+ <a href="/docs" class="btn">مشاهده مستندات فنی</a>
69
  </div>
70
  </body>
71
  </html>
72
  """
73
 
74
  # ==========================================
75
+ # ۳. پنل مدیریت (Engineering Mode) - آدرس /admin
76
  # ==========================================
77
  @app.get("/admin", response_class=HTMLResponse)
78
  async def admin_ui():
 
80
  <!DOCTYPE html>
81
  <html>
82
  <head>
83
+ <title>Engineering Panel | Behrad AI</title>
84
  <style>
85
+ body {{ background: #080808; color: #4af626; font-family: 'Courier New', monospace; padding: 40px; }}
86
+ .panel {{ border: 1px solid #4af626; padding: 30px; border-radius: 8px; box-shadow: 0 0 25px rgba(74, 246, 38, 0.15); }}
87
+ .stats {{ display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-top: 30px; }}
88
  .stat-box {{ border: 1px dashed #4af626; padding: 20px; text-align: center; }}
89
+ .stat-box div {{ font-size: 32px; font-weight: bold; margin-top: 10px; }}
90
+ .badge {{ color: black; background: #4af626; padding: 2px 10px; border-radius: 4px; font-weight: bold; }}
91
  </style>
92
  </head>
93
  <body>
94
+ <div class="panel">
95
+ <h2>[ BEHRAD_AI_CORE_SYSTEM_LOG ] <span class="badge">V3.1</span></h2>
96
+ <p>MODEL: gemini-1.5-flash-latest | STATUS: RUNNING</p>
97
+ <div class="stats">
98
  <div class="stat-box">REQUESTS<div>{stats['total_requests']}</div></div>
99
  <div class="stat-box">SUCCESS<div>{stats['success_count']}</div></div>
100
  <div class="stat-box">ERRORS<div>{stats['error_count']}</div></div>
101
  <div class="stat-box">KEYS<div>{len(API_KEYS)}</div></div>
102
  </div>
103
+ <div style="margin-top: 20px; font-size: 13px; opacity: 0.7;">
104
+ > Start Time: {stats['start_time']}<br>
105
+ > Auto-rotation: ENABLED<br>
106
+ > Security Layer: x-api-token active
107
+ </div>
108
  </div>
109
  </body>
110
  </html>
111
  """
112
 
113
  # ==========================================
114
+ # ۴. هسته پردازشی (Anti-Limit & High Speed)
115
  # ==========================================
116
  @app.post("/ask")
117
  async def ask_ai(request: AIRequest, x_api_token: str = Header(...)):
118
+ # بررسی امنیت
119
  if x_api_token != MY_SECRET_PASS:
120
  stats["error_count"] += 1
121
+ raise HTTPException(status_code=403, detail="⛔ Access Denied: رمز عبور نامعتبر است!")
122
 
123
  stats["total_requests"] += 1
124
+
125
+ # انتخاب کلید بعدی از چرخه برای دور زدن محدودیت
126
  current_key = next(key_cycle)
127
 
128
  try:
129
+ # پیکربندی مجدد در هر درخواست (برای حل ارور No API_KEY)
130
  genai.configure(api_key=current_key)
131
 
132
+ # استفاده از مدل درخواستی شما
133
+ model = genai.GenerativeModel('gemini-1.5-flash-latest')
134
 
135
  response = model.generate_content(request.prompt)
136
 
 
138
  return {
139
  "status": "success",
140
  "answer": response.text,
141
+ "credits": "Generated by Behrad AI Core"
142
  }
143
 
144
  except Exception as e:
145
  stats["error_count"] += 1
146
  return {
147
  "status": "error",
148
+ "message": "سیستم در حال چرخش کلید است. لطفاً دوباره تلاش کنید.",
149
+ "debug": str(e)
150
  }