BehradB2 commited on
Commit
047cb6c
·
verified ·
1 Parent(s): a47ed90

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. main.py +90 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . /code
10
+
11
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException, Header, Depends
2
+ from fastapi.responses import HTMLResponse
3
+ from fastapi.middleware.cors import CORSMiddleware
4
+ from pydantic import BaseModel
5
+ import google.generativeai as genai
6
+ import os
7
+
8
+ # ==========================================
9
+ # تنظیمات امنیتی و هوش مصنوعی
10
+ # ==========================================
11
+
12
+ # 1. کلید جمنای (این رو بعداً تو تنظیمات سرور وارد میکنیم که امن بمونه)
13
+ # اگر خواستی تست کنی، موقتاً کلیدت رو جای os.environ... بذار
14
+ GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
15
+
16
+ # 2. رمز عبور API تو (که فقط خودت و پروژه‌هات بتونن استفاده کنن)
17
+ MY_SECRET_PASS = "Behrad_King_2026" # این رمز رو عوض کن!
18
+
19
+ genai.configure(api_key=GEMINI_API_KEY)
20
+ model = genai.GenerativeModel('gemini-1.5-flash')
21
+
22
+ app = FastAPI(title="Behrad AI Core", docs_url="/docs")
23
+
24
+ # تنظیمات CORS (آزادسازی برای همه پروژه‌ها)
25
+ app.add_middleware(
26
+ CORSMiddleware,
27
+ allow_origins=["*"],
28
+ allow_credentials=True,
29
+ allow_methods=["*"],
30
+ allow_headers=["*"],
31
+ )
32
+
33
+ # مدل ورودی
34
+ class AIRequest(BaseModel):
35
+ prompt: str
36
+
37
+ # تابع چک کردن رمز (Security Check)
38
+ async def verify_token(x_api_token: str = Header(...)):
39
+ if x_api_token != MY_SECRET_PASS:
40
+ raise HTTPException(status_code=400, detail="⛔ Access Denied: رمز اشتباه است!")
41
+
42
+ # ==========================================
43
+ # ظاهر گرافیکی (UI) - HTML/CSS
44
+ # ==========================================
45
+ @app.get("/", response_class=HTMLResponse)
46
+ async def read_root():
47
+ return """
48
+ <!DOCTYPE html>
49
+ <html>
50
+ <head>
51
+ <title>Behrad AI Server</title>
52
+ <style>
53
+ body { background-color: #0d1117; color: #00ff41; font-family: 'Courier New', monospace; text-align: center; padding-top: 50px; }
54
+ h1 { font-size: 3em; text-shadow: 0 0 10px #00ff41; }
55
+ .status { border: 2px solid #00ff41; padding: 20px; display: inline-block; border-radius: 10px; box-shadow: 0 0 20px #00ff41; }
56
+ .blink { animation: blinker 1.5s linear infinite; }
57
+ @keyframes blinker { 50% { opacity: 0; } }
58
+ p { font-size: 1.2em; }
59
+ </style>
60
+ </head>
61
+ <body>
62
+ <div class="status">
63
+ <h1>SYSTEM ONLINE</h1>
64
+ <p>Server Status: <span class="blink">ACTIVE</span></p>
65
+ <p>Owner: Behrad Besharati</p>
66
+ <p>Location: Secure Cloud (Anti-Sanction)</p>
67
+ <hr style="border-color: #00ff41;">
68
+ <p>برای استفاده از API به آدرس /docs بروید</p>
69
+ </div>
70
+ </body>
71
+ </html>
72
+ """
73
+
74
+ # ==========================================
75
+ # اندپوینت اصلی (مغز هوش مصنوعی)
76
+ # ==========================================
77
+ @app.post("/ask", dependencies=[Depends(verify_token)])
78
+ async def ask_ai(request: AIRequest):
79
+ try:
80
+ if not GEMINI_API_KEY:
81
+ return {"error": "کلید جمنای تنظیم نشده است!"}
82
+
83
+ response = model.generate_content(request.prompt)
84
+ return {
85
+ "status": "success",
86
+ "answer": response.text,
87
+ "credits": "Generated by Behrad AI"
88
+ }
89
+ except Exception as e:
90
+ return {"status": "error", "message": str(e)}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ google-generativeai
4
+ pydantic
5
+ jinja2
6
+ python-multipart