ibrahimlasfar commited on
Commit
5243061
·
1 Parent(s): a374e98

Refined core logic and sprinkled some magic

Browse files
main.py CHANGED
@@ -1,14 +1,17 @@
1
  import os
2
  import logging
3
- from fastapi import FastAPI
4
- from fastapi.responses import HTMLResponse
5
  from fastapi.staticfiles import StaticFiles
6
  from fastapi.templating import Jinja2Templates
7
- from starlette.requests import Request
8
  import gradio as gr
9
  from api.endpoints import router as api_router
10
- from utils.generation import generate, format_final, LATEX_DELIMS
11
  from utils.web_search import web_search
 
 
 
12
 
13
  # إعداد التسجيل
14
  logging.basicConfig(level=logging.INFO)
@@ -20,18 +23,41 @@ logger.info("Files in /app/: %s", os.listdir("/app"))
20
  # إعداد العميل لـ Hugging Face Inference API
21
  HF_TOKEN = os.getenv("HF_TOKEN")
22
  if not HF_TOKEN:
23
- logger.error("HF_TOKEN is not set in environment variables.")
24
  raise ValueError("HF_TOKEN is required for Inference API.")
25
 
 
 
 
 
 
26
  # إعدادات الـ queue
27
  QUEUE_SIZE = int(os.getenv("QUEUE_SIZE", 80))
28
  CONCURRENCY_LIMIT = int(os.getenv("CONCURRENCY_LIMIT", 20))
29
 
30
- # إعداد CSS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  css = """
32
- .gradio-container { max-width: 800px; margin: auto; }
33
- .chatbot { border: 1px solid #ccc; border-radius: 10px; }
34
- .input-textbox { font-size: 16px; }
 
35
  """
36
 
37
  # إعداد واجهة Gradio
@@ -41,13 +67,21 @@ chatbot_ui = gr.ChatInterface(
41
  chatbot=gr.Chatbot(
42
  label="MGZon Chatbot",
43
  type="messages",
44
- height=600,
45
  latex_delimiters=LATEX_DELIMS,
 
 
 
 
46
  ),
47
  additional_inputs_accordion=gr.Accordion("⚙️ Settings", open=True),
48
  additional_inputs=[
49
- gr.Textbox(label="System prompt", value="You are a helpful assistant capable of code generation, analysis, review, and more.", lines=2),
50
- gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, step=0.1, value=0.9),
 
 
 
 
51
  gr.Radio(label="Reasoning Effort", choices=["low", "medium", "high"], value="medium"),
52
  gr.Checkbox(label="Enable DeepSearch (web browsing)", value=True),
53
  gr.Slider(label="Max New Tokens", minimum=50, maximum=128000, step=50, value=4096),
@@ -60,34 +94,86 @@ chatbot_ui = gr.ChatInterface(
60
  ["Analyze the performance of a Django REST API."],
61
  ["Tell me about MGZon products and services."],
62
  ["Create a Flask route for user authentication."],
 
63
  ["What are the latest trends in AI?"],
64
  ["Provide guidelines for publishing a technical blog post."],
65
  ["Who is the founder of MGZon?"],
66
  ],
67
  title="MGZon Chatbot",
68
- description="A versatile chatbot powered by GPT-OSS-20B and a fine-tuned model for MGZon queries. Supports code generation, analysis, review, web search, and MGZon-specific queries. Licensed under Apache 2.0. ***DISCLAIMER:*** Analysis may contain internal thoughts not suitable for final response.",
 
 
 
 
69
  theme="gradio/soft",
70
  css=css,
71
  )
72
 
73
- # إعداد FastAPI
74
- app = FastAPI(title="MGZon Chatbot API")
75
-
76
  # ربط Gradio مع FastAPI
77
  app = gr.mount_gradio_app(app, chatbot_ui, path="/gradio")
78
 
79
- # ربط الملفات الثابتة والقوالب
80
- app.mount("/static", StaticFiles(directory="static"), name="static")
81
- templates = Jinja2Templates(directory="templates")
 
 
 
 
 
 
 
 
82
 
83
- # تضمين API endpoints
84
- app.include_router(api_router)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  # Root endpoint
87
  @app.get("/", response_class=HTMLResponse)
88
  async def root(request: Request):
89
  return templates.TemplateResponse("index.html", {"request": request})
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  # تشغيل الخادم
92
  if __name__ == "__main__":
93
  import uvicorn
 
1
  import os
2
  import logging
3
+ from fastapi import FastAPI, Request, HTTPException
4
+ from fastapi.responses import HTMLResponse, RedirectResponse, JSONResponse
5
  from fastapi.staticfiles import StaticFiles
6
  from fastapi.templating import Jinja2Templates
7
+ from starlette.middleware.base import BaseHTTPMiddleware
8
  import gradio as gr
9
  from api.endpoints import router as api_router
10
+ from utils.generation import generate, LATEX_DELIMS
11
  from utils.web_search import web_search
12
+ from fastapi.security import OAuth2PasswordBearer
13
+ from datetime import datetime, timedelta
14
+ from jose import JWTError, jwt
15
 
16
  # إعداد التسجيل
17
  logging.basicConfig(level=logging.INFO)
 
23
  # إعداد العميل لـ Hugging Face Inference API
24
  HF_TOKEN = os.getenv("HF_TOKEN")
25
  if not HF_TOKEN:
26
+ logger.error("HF_TOKEN is not set.")
27
  raise ValueError("HF_TOKEN is required for Inference API.")
28
 
29
+ # إعدادات JWT لـ OAuth 2.0
30
+ SECRET_KEY = os.getenv("JWT_SECRET_KEY", "your-secret-key") # غيّرها في الإنتاج
31
+ ALGORITHM = "HS256"
32
+ ACCESS_TOKEN_EXPIRE_MINUTES = 30
33
+
34
  # إعدادات الـ queue
35
  QUEUE_SIZE = int(os.getenv("QUEUE_SIZE", 80))
36
  CONCURRENCY_LIMIT = int(os.getenv("CONCURRENCY_LIMIT", 20))
37
 
38
+ # إعداد OAuth2
39
+ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/oauth/token")
40
+
41
+ # إعداد FastAPI
42
+ app = FastAPI(
43
+ title="MGZon Chatbot API",
44
+ description="API for MGZon Chatbot with support for code generation, analysis, and MGZon-specific queries.",
45
+ version="1.0.0",
46
+ )
47
+
48
+ # ربط الملفات الثابتة والقوالب
49
+ app.mount("/static", StaticFiles(directory="static"), name="static")
50
+ templates = Jinja2Templates(directory="templates")
51
+
52
+ # تضمين API endpoints
53
+ app.include_router(api_router)
54
+
55
+ # إعداد CSS لـ Gradio
56
  css = """
57
+ .gradio-container { max-width: 900px; margin: auto; }
58
+ .chatbot { border: 2px solid #ff6f61; border-radius: 15px; background: rgba(255, 255, 255, 0.05); }
59
+ .input-textbox { font-size: 18px; border-radius: 10px; }
60
+ .submit-btn { background: linear-gradient(45deg, #ff6f61, #e55a50); }
61
  """
62
 
63
  # إعداد واجهة Gradio
 
67
  chatbot=gr.Chatbot(
68
  label="MGZon Chatbot",
69
  type="messages",
70
+ height=700,
71
  latex_delimiters=LATEX_DELIMS,
72
+ avatar_images=(
73
+ "https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg",
74
+ "https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg",
75
+ ),
76
  ),
77
  additional_inputs_accordion=gr.Accordion("⚙️ Settings", open=True),
78
  additional_inputs=[
79
+ gr.Textbox(
80
+ label="System prompt",
81
+ value="You are a helpful assistant capable of code generation, analysis, review, and more. Support frameworks like React, Django, Flask, Rails, Laravel, and others.",
82
+ lines=2,
83
+ ),
84
+ gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, step=0.1, value=0.7),
85
  gr.Radio(label="Reasoning Effort", choices=["low", "medium", "high"], value="medium"),
86
  gr.Checkbox(label="Enable DeepSearch (web browsing)", value=True),
87
  gr.Slider(label="Max New Tokens", minimum=50, maximum=128000, step=50, value=4096),
 
94
  ["Analyze the performance of a Django REST API."],
95
  ["Tell me about MGZon products and services."],
96
  ["Create a Flask route for user authentication."],
97
+ ["Generate a Laravel controller for user management."],
98
  ["What are the latest trends in AI?"],
99
  ["Provide guidelines for publishing a technical blog post."],
100
  ["Who is the founder of MGZon?"],
101
  ],
102
  title="MGZon Chatbot",
103
+ description=(
104
+ "A versatile chatbot powered by GPT-OSS-20B and MGZON/Veltrix. Supports code generation, analysis, review, web search, and MGZon-specific queries. "
105
+ "Built by <a href='https://mark-elasfar.web.app/' target='_blank'>Mark Al-Asfar</a>. "
106
+ "Licensed under Apache 2.0. <strong>DISCLAIMER:</strong> Analysis may contain internal thoughts not suitable for final response."
107
+ ),
108
  theme="gradio/soft",
109
  css=css,
110
  )
111
 
 
 
 
112
  # ربط Gradio مع FastAPI
113
  app = gr.mount_gradio_app(app, chatbot_ui, path="/gradio")
114
 
115
+ # Middleware لمعالجة 404
116
+ class NotFoundMiddleware(BaseHTTPMiddleware):
117
+ async def dispatch(self, request: Request, call_next):
118
+ try:
119
+ response = await call_next(request)
120
+ if response.status_code == 404:
121
+ return templates.TemplateResponse("404.html", {"request": request}, status_code=404)
122
+ return response
123
+ except Exception as e:
124
+ logger.exception(f"Error processing request: {e}")
125
+ return templates.TemplateResponse("404.html", {"request": request}, status_code=404)
126
 
127
+ app.add_middleware(NotFoundMiddleware)
128
+
129
+ # OAuth 2.0 token endpoint (مثال أولي)
130
+ @app.post("/oauth/token")
131
+ async def token():
132
+ """إنشاء رمز OAuth 2.0 (مثال أولي)."""
133
+ access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
134
+ access_token = jwt.encode(
135
+ {"sub": "mgzon_user", "exp": datetime.utcnow() + access_token_expires},
136
+ SECRET_KEY,
137
+ algorithm=ALGORITHM,
138
+ )
139
+ return {"access_token": access_token, "token_type": "bearer"}
140
+
141
+ # Health check endpoint
142
+ @app.get("/api/health")
143
+ async def health_check():
144
+ """فحص حالة النموذج والخدمة."""
145
+ try:
146
+ # اختبار اتصال بسيط بنموذج افتراضي
147
+ client = OpenAI(api_key=HF_TOKEN, base_url=FALLBACK_API_ENDPOINT, timeout=10.0)
148
+ client.chat.completions.create(
149
+ model=TERTIARY_MODEL_NAME,
150
+ messages=[{"role": "user", "content": "Ping"}],
151
+ max_tokens=10,
152
+ )
153
+ return JSONResponse({"status": "healthy", "model": TERTIARY_MODEL_NAME})
154
+ except Exception as e:
155
+ logger.error(f"Health check failed: {e}")
156
+ return JSONResponse({"status": "unhealthy", "error": str(e)}, status_code=503)
157
 
158
  # Root endpoint
159
  @app.get("/", response_class=HTMLResponse)
160
  async def root(request: Request):
161
  return templates.TemplateResponse("index.html", {"request": request})
162
 
163
+ # Docs endpoint
164
+ @app.get("/docs", response_class=HTMLResponse)
165
+ async def docs(request: Request):
166
+ return templates.TemplateResponse("docs.html", {"request": request})
167
+
168
+ # Redirect لـ /gradio
169
+ @app.get("/launch-chatbot", response_class=RedirectResponse)
170
+ async def launch_chatbot():
171
+ try:
172
+ return RedirectResponse(url="/gradio")
173
+ except Exception as e:
174
+ logger.error(f"Failed to redirect to /gradio: {e}")
175
+ raise HTTPException(status_code=500, detail="Failed to redirect to chatbot")
176
+
177
  # تشغيل الخادم
178
  if __name__ == "__main__":
179
  import uvicorn
static/css/styles.css CHANGED
@@ -2,29 +2,77 @@ body {
2
  font-family: 'Arial', sans-serif;
3
  margin: 0;
4
  padding: 0;
5
- background: linear-gradient(135deg, #1e3c72, #2a5298);
 
 
6
  color: #fff;
7
  min-height: 100vh;
8
- overflow-x: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  }
10
 
11
  .container {
12
  max-width: 1200px;
13
- margin: auto;
14
  padding: 20px;
15
- text-align: center;
16
  }
17
 
18
  .logo {
19
- width: 100px;
20
- height: 100px;
21
  margin-bottom: 20px;
 
22
  }
23
 
24
  h1 {
25
- font-size: 3rem;
26
  margin-bottom: 20px;
27
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
 
28
  }
29
 
30
  p {
@@ -36,65 +84,85 @@ p {
36
  .btn {
37
  display: inline-block;
38
  padding: 15px 30px;
39
- background: #ff6f61;
40
  color: #fff;
41
  text-decoration: none;
42
  border-radius: 25px;
43
  font-size: 1.1rem;
44
- transition: background 0.3s, transform 0.2s;
45
  }
46
 
47
  .btn:hover {
48
- background: #e55a50;
49
- transform: scale(1.05);
50
  }
51
 
52
- .features, .docs {
53
  margin-top: 40px;
54
  text-align: left;
55
  }
56
 
57
- .features h2, .docs h2 {
58
- font-size: 1.8rem;
59
- margin-bottom: 15px;
60
  text-align: center;
 
61
  }
62
 
63
- .feature-grid, .footer-grid {
64
  display: grid;
65
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
66
  gap: 20px;
67
  }
68
 
69
- .feature-card, .footer-card {
70
  background: rgba(255, 255, 255, 0.1);
71
  padding: 20px;
72
  border-radius: 10px;
73
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
74
- transition: transform 0.3s, box-shadow 0.3s;
75
  text-align: center;
 
76
  }
77
 
78
- .feature-card:hover, .footer-card:hover {
79
  transform: scale(1.05);
80
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
 
81
  }
82
 
83
  .feature-card i, .footer-card i {
84
- font-size: 2rem;
85
  margin-bottom: 10px;
86
  color: #ff6f61;
87
  }
88
 
 
 
 
 
 
 
 
 
 
 
89
  .code-block {
90
  position: relative;
91
  margin-bottom: 20px;
92
- }
93
-
94
- .code-block pre {
95
  background: #1a1a1a;
96
  padding: 20px;
97
  border-radius: 10px;
 
 
 
 
 
 
 
 
 
 
98
  color: #c9e4ca;
99
  font-family: 'Courier New', monospace;
100
  overflow-x: auto;
@@ -110,6 +178,7 @@ p {
110
  border: none;
111
  border-radius: 5px;
112
  cursor: pointer;
 
113
  }
114
 
115
  .copy-btn:hover {
@@ -131,24 +200,37 @@ footer {
131
  }
132
 
133
  .footer-logo {
134
- width: 80px;
135
- height: 80px;
136
  margin-bottom: 20px;
 
137
  }
138
 
139
  .footer-social a {
140
- font-size: 1.5rem;
141
  color: #fff;
142
- margin: 0 10px;
143
- transition: color 0.3s;
144
  }
145
 
146
  .footer-social a:hover {
147
  color: #ff6f61;
 
148
  }
149
 
150
- @keyframes gradient {
151
- 0% { background-position: 0% 50%; }
152
- 50% { background-position: 100% 50%; }
153
- 100% { background-position: 0% 50%; }
 
 
 
 
 
 
 
 
 
 
 
154
  }
 
2
  font-family: 'Arial', sans-serif;
3
  margin: 0;
4
  padding: 0;
5
+ background: linear-gradient(45deg, #1e3c72, #2a5298, #ff6f61, #1e3c72);
6
+ background-size: 400% 400%;
7
+ animation: gradient 15s ease infinite;
8
  color: #fff;
9
  min-height: 100vh;
10
+ display: flex;
11
+ }
12
+
13
+ @keyframes gradient {
14
+ 0% { background-position: 0% 50%; }
15
+ 50% { background-position: 100% 50%; }
16
+ 100% { background-position: 0% 50%; }
17
+ }
18
+
19
+ .sidebar {
20
+ width: 250px;
21
+ background: rgba(0, 0, 0, 0.8);
22
+ padding: 20px;
23
+ height: 100vh;
24
+ position: fixed;
25
+ top: 0;
26
+ left: 0;
27
+ display: flex;
28
+ flex-direction: column;
29
+ align-items: center;
30
+ }
31
+
32
+ .sidebar-logo {
33
+ width: 80px;
34
+ height: 80px;
35
+ margin-bottom: 20px;
36
+ filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
37
+ }
38
+
39
+ .sidebar nav {
40
+ display: flex;
41
+ flex-direction: column;
42
+ gap: 10px;
43
+ }
44
+
45
+ .sidebar nav a {
46
+ color: #fff;
47
+ text-decoration: none;
48
+ padding: 10px;
49
+ border-radius: 5px;
50
+ transition: background 0.3s;
51
+ }
52
+
53
+ .sidebar nav a:hover, .sidebar nav a.active {
54
+ background: #ff6f61;
55
  }
56
 
57
  .container {
58
  max-width: 1200px;
59
+ margin-left: 270px;
60
  padding: 20px;
61
+ flex: 1;
62
  }
63
 
64
  .logo {
65
+ width: 120px;
66
+ height: 120px;
67
  margin-bottom: 20px;
68
+ filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
69
  }
70
 
71
  h1 {
72
+ font-size: 3.5rem;
73
  margin-bottom: 20px;
74
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
75
+ animation: fadeIn 1s ease-in-out;
76
  }
77
 
78
  p {
 
84
  .btn {
85
  display: inline-block;
86
  padding: 15px 30px;
87
+ background: linear-gradient(45deg, #ff6f61, #e55a50);
88
  color: #fff;
89
  text-decoration: none;
90
  border-radius: 25px;
91
  font-size: 1.1rem;
92
+ transition: transform 0.3s, box-shadow 0.3s;
93
  }
94
 
95
  .btn:hover {
96
+ transform: scale(1.1);
97
+ box-shadow: 0 4px 15px rgba(255, 111, 97, 0.5);
98
  }
99
 
100
+ .features, .docs, .news {
101
  margin-top: 40px;
102
  text-align: left;
103
  }
104
 
105
+ .features h2, .docs h2, .news h2 {
106
+ font-size: 2rem;
107
+ margin-bottom: 20px;
108
  text-align: center;
109
+ color: #fff;
110
  }
111
 
112
+ .feature-grid, .footer-grid, .news-grid {
113
  display: grid;
114
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
115
  gap: 20px;
116
  }
117
 
118
+ .feature-card, .footer-card, .news-card {
119
  background: rgba(255, 255, 255, 0.1);
120
  padding: 20px;
121
  border-radius: 10px;
122
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
123
+ transition: transform 0.3s, box-shadow 0.3s, background 0.3s;
124
  text-align: center;
125
+ aspect-ratio: 1/1;
126
  }
127
 
128
+ .feature-card:hover, .footer-card:hover, .news-card:hover {
129
  transform: scale(1.05);
130
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
131
+ background: rgba(255, 255, 255, 0.2);
132
  }
133
 
134
  .feature-card i, .footer-card i {
135
+ font-size: 2.5rem;
136
  margin-bottom: 10px;
137
  color: #ff6f61;
138
  }
139
 
140
+ .news-card a {
141
+ color: #ff6f61;
142
+ text-decoration: none;
143
+ font-weight: bold;
144
+ }
145
+
146
+ .news-card a:hover {
147
+ text-decoration: underline;
148
+ }
149
+
150
  .code-block {
151
  position: relative;
152
  margin-bottom: 20px;
 
 
 
153
  background: #1a1a1a;
154
  padding: 20px;
155
  border-radius: 10px;
156
+ }
157
+
158
+ .code-block h3 {
159
+ color: #ff6f61;
160
+ margin-bottom: 10px;
161
+ }
162
+
163
+ .code-block pre {
164
+ background: transparent;
165
+ padding: 0;
166
  color: #c9e4ca;
167
  font-family: 'Courier New', monospace;
168
  overflow-x: auto;
 
178
  border: none;
179
  border-radius: 5px;
180
  cursor: pointer;
181
+ transition: background 0.3s;
182
  }
183
 
184
  .copy-btn:hover {
 
200
  }
201
 
202
  .footer-logo {
203
+ width: 100px;
204
+ height: 100px;
205
  margin-bottom: 20px;
206
+ filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.5));
207
  }
208
 
209
  .footer-social a {
210
+ font-size: 1.8rem;
211
  color: #fff;
212
+ margin: 0 15px;
213
+ transition: color 0.3s, transform 0.3s;
214
  }
215
 
216
  .footer-social a:hover {
217
  color: #ff6f61;
218
+ transform: scale(1.2);
219
  }
220
 
221
+ @keyframes fadeIn {
222
+ from { opacity: 0; transform: translateY(20px); }
223
+ to { opacity: 1; transform: translateY(0); }
224
+ }
225
+
226
+ @media (max-width: 768px) {
227
+ .sidebar {
228
+ width: 100%;
229
+ height: auto;
230
+ position: static;
231
+ padding: 10px;
232
+ }
233
+ .container {
234
+ margin-left: 0;
235
+ }
236
  }
static/js/scripts.js CHANGED
@@ -6,7 +6,30 @@ function copyCode(button) {
6
  });
7
  }
8
 
9
- document.getElementById('chatbot-link').addEventListener('click', (e) => {
10
  e.preventDefault();
11
  window.location.href = '/gradio';
12
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  });
7
  }
8
 
9
+ document.getElementById('chatbot-link')?.addEventListener('click', (e) => {
10
  e.preventDefault();
11
  window.location.href = '/gradio';
12
  });
13
+
14
+ // تأثيرات للكروت
15
+ document.querySelectorAll('.feature-card, .footer-card, .news-card').forEach(card => {
16
+ card.addEventListener('mouseenter', () => {
17
+ card.style.transform = 'scale(1.05) rotate(1deg)';
18
+ });
19
+ card.addEventListener('mouseleave', () => {
20
+ card.style.transform = 'scale(1) rotate(0deg)';
21
+ });
22
+ });
23
+
24
+ // إغلاق/فتح الـ sidebar على الموبايل
25
+ document.addEventListener('DOMContentLoaded', () => {
26
+ const sidebar = document.querySelector('.sidebar');
27
+ const toggleBtn = document.createElement('button');
28
+ toggleBtn.textContent = '☰';
29
+ toggleBtn.className = 'sidebar-toggle';
30
+ document.body.prepend(toggleBtn);
31
+
32
+ toggleBtn.addEventListener('click', () => {
33
+ sidebar.classList.toggle('active');
34
+ });
35
+ });
templates/404.html ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>404 - Page Not Found</title>
7
+ <link rel="stylesheet" href="/static/css/styles.css">
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css" rel="stylesheet">
9
+ </head>
10
+ <body>
11
+ <div class="container">
12
+ <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="logo">
13
+ <h1>404 - Page Not Found 😕</h1>
14
+ <p>Oops! Looks like you wandered into the wrong corner of the internet.</p>
15
+ <a href="/" class="btn">Back to Home</a>
16
+ </div>
17
+ <footer>
18
+ <div class="footer-container">
19
+ <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="footer-logo">
20
+ <p>Developed by <a href="https://mark-elasfar.web.app/" target="_blank">Mark Al-Asfar</a> | Powered by MGZon AI</p>
21
+ <div class="footer-social">
22
+ <a href="https://github.com/Mark-Lasfar/MGZon"><i class="bx bxl-github"></i></a>
23
+ <a href="https://x.com/MGZon"><i class="bx bxl-twitter"></i></a>
24
+ <a href="https://www.facebook.com/people/Mark-Al-Asfar/pfbid02GMisUQ8AqWkNZjoKtWFHH1tbdHuVscN1cjcFnZWy9HkRaAsmanBfT6mhySAyqpg4l/"><i class="bx bxl-facebook"></i></a>
25
+ </div>
26
+ <p>© 2025 Mark Al-Asfar & MGZon AI. All rights reserved.</p>
27
+ </div>
28
+ </footer>
29
+ <script src="/static/js/scripts.js"></script>
30
+ </body>
31
+ </html>
templates/docs.html ADDED
@@ -0,0 +1,281 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>MGZon API Documentation</title>
7
+ <link rel="stylesheet" href="/static/css/styles.css">
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css" rel="stylesheet">
9
+ </head>
10
+ <body>
11
+ <div class="sidebar">
12
+ <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="sidebar-logo">
13
+ <nav>
14
+ <a href="/">Home</a>
15
+ <a href="/docs" class="active">API Documentation</a>
16
+ <a href="https://hager-zon.vercel.app/about">About MGZon</a>
17
+ <a href="https://hager-zon.vercel.app/community">Community</a>
18
+ <a href="https://mark-elasfar.web.app/" target="_blank">Mark Al-Asfar</a>
19
+ </nav>
20
+ </div>
21
+ <div class="container">
22
+ <h1>MGZon API Documentation 📚</h1>
23
+ <p>
24
+ Integrate MGZon Chatbot into your projects with our API. Supports Python (Django, Flask, FastAPI), JavaScript (React, Node.js, Express), Ruby (Rails), PHP (Laravel), and more. Explore the examples below to get started.
25
+ </p>
26
+ <div class="docs">
27
+ <h2>Endpoints</h2>
28
+ <div class="code-block">
29
+ <h3>POST /api/chat</h3>
30
+ <p>Send a chat message to the MGZon Chatbot and get a response.</p>
31
+ <pre><code class="language-json">{
32
+ "message": "Your query here",
33
+ "system_prompt": "You are a helpful assistant",
34
+ "history": [{"role": "user", "content": "Previous message"}, {"role": "assistant", "content": "Previous response"}],
35
+ "temperature": 0.7,
36
+ "max_new_tokens": 4096,
37
+ "enable_browsing": false
38
+ }</code></pre>
39
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
40
+ </div>
41
+ <div class="code-block">
42
+ <h3>Python (requests) - Chat</h3>
43
+ <p>Make a chat request using Python's requests library.</p>
44
+ <pre><code class="language-python">import requests
45
+
46
+ response = requests.post(
47
+ "https://hager-zon.vercel.app/api/chat",
48
+ json={
49
+ "message": "Generate a React component",
50
+ "system_prompt": "You are a coding expert",
51
+ "temperature": 0.7,
52
+ "max_new_tokens": 4096
53
+ }
54
+ )
55
+ print(response.json())</code></pre>
56
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
57
+ </div>
58
+ <div class="code-block">
59
+ <h3>Python (Django) - Chat</h3>
60
+ <p>Integrate with a Django project.</p>
61
+ <pre><code class="language-python">import requests
62
+ from django.http import JsonResponse
63
+ from django.views import View
64
+
65
+ class ChatView(View):
66
+ def post(self, request):
67
+ data = request.POST.get('message')
68
+ response = requests.post(
69
+ "https://hager-zon.vercel.app/api/chat",
70
+ json={"message": data, "system_prompt": "You are a coding expert", "temperature": 0.7}
71
+ )
72
+ return JsonResponse(response.json())</code></pre>
73
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
74
+ </div>
75
+ <div class="code-block">
76
+ <h3>Python (Flask) - Chat</h3>
77
+ <p>Integrate with a Flask app.</p>
78
+ <pre><code class="language-python">from flask import Flask, request, jsonify
79
+ import requests
80
+
81
+ app = Flask(__name__)
82
+
83
+ @app.route('/chat', methods=['POST'])
84
+ def chat():
85
+ data = request.json.get('message')
86
+ response = requests.post(
87
+ "https://hager-zon.vercel.app/api/chat",
88
+ json={"message": data, "system_prompt": "You are a coding expert", "temperature": 0.7}
89
+ )
90
+ return jsonify(response.json())</code></pre>
91
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
92
+ </div>
93
+ <div class="code-block">
94
+ <h3>JavaScript (React) - Chat</h3>
95
+ <p>Integrate with a React app using fetch.</p>
96
+ <pre><code class="language-javascript">import React, { useState } from 'react';
97
+
98
+ function ChatComponent() {
99
+ const [message, setMessage] = useState('');
100
+ const [response, setResponse] = useState('');
101
+
102
+ const handleSubmit = async () => {
103
+ const res = await fetch('https://hager-zon.vercel.app/api/chat', {
104
+ method: 'POST',
105
+ headers: { 'Content-Type': 'application/json' },
106
+ body: JSON.stringify({
107
+ message,
108
+ system_prompt: 'You are a coding expert',
109
+ temperature: 0.7,
110
+ max_new_tokens: 4096
111
+ })
112
+ });
113
+ const data = await res.json();
114
+ setResponse(data.response);
115
+ };
116
+
117
+ return (
118
+ <div>
119
+ <input type="text" value={message} onChange={(e) => setMessage(e.target.value)} />
120
+ <button onClick={handleSubmit}>Send</button>
121
+ <p>{response}</p>
122
+ </div>
123
+ );
124
+ }
125
+
126
+ export default ChatComponent;</code></pre>
127
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
128
+ </div>
129
+ <div class="code-block">
130
+ <h3>JavaScript (Node.js/Express) - Chat</h3>
131
+ <p>Integrate with a Node.js/Express server.</p>
132
+ <pre><code class="language-javascript">const express = require('express');
133
+ const fetch = require('node-fetch');
134
+ const app = express();
135
+
136
+ app.use(express.json());
137
+
138
+ app.post('/chat', async (req, res) => {
139
+ const { message } = req.body;
140
+ const response = await fetch('https://hager-zon.vercel.app/api/chat', {
141
+ method: 'POST',
142
+ headers: { 'Content-Type': 'application/json' },
143
+ body: JSON.stringify({
144
+ message,
145
+ system_prompt: 'You are a coding expert',
146
+ temperature: 0.7,
147
+ max_new_tokens: 4096
148
+ })
149
+ });
150
+ const data = await response.json();
151
+ res.json(data);
152
+ });
153
+
154
+ app.listen(3000, () => console.log('Server running on port 3000'));</code></pre>
155
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
156
+ </div>
157
+ <div class="code-block">
158
+ <h3>Ruby (Rails) - Chat</h3>
159
+ <p>Integrate with a Ruby on Rails app.</p>
160
+ <pre><code class="language-ruby">require 'httparty'
161
+
162
+ class ChatController < ApplicationController
163
+ def create
164
+ response = HTTParty.post(
165
+ 'https://hager-zon.vercel.app/api/chat',
166
+ body: {
167
+ message: params[:message],
168
+ system_prompt: 'You are a coding expert',
169
+ temperature: 0.7,
170
+ max_new_tokens: 4096
171
+ }.to_json,
172
+ headers: { 'Content-Type' => 'application/json' }
173
+ )
174
+ render json: response.parsed_response
175
+ end
176
+ end</code></pre>
177
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
178
+ </div>
179
+ <div class="code-block">
180
+ <h3>PHP (Laravel) - Chat</h3>
181
+ <p>Integrate with a Laravel app.</p>
182
+ <pre><code class="language-php">use Illuminate\Support\Facades\Http;
183
+
184
+ class ChatController extends Controller
185
+ {
186
+ public function chat(Request $request)
187
+ {
188
+ $response = Http::post('https://hager-zon.vercel.app/api/chat', [
189
+ 'message' => $request->input('message'),
190
+ 'system_prompt' => 'You are a coding expert',
191
+ 'temperature' => 0.7,
192
+ 'max_new_tokens' => 4096
193
+ ]);
194
+ return $response->json();
195
+ }
196
+ }</code></pre>
197
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
198
+ </div>
199
+ <div class="code-block">
200
+ <h3>Bash (cURL) - Chat</h3>
201
+ <pre><code class="language-bash">curl -X POST https://hager-zon.vercel.app/api/chat \
202
+ -H "Content-Type: application/json" \
203
+ -d '{"message":"Generate a React component","system_prompt":"You are a coding expert","temperature":0.7,"max_new_tokens":4096}'</code></pre>
204
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
205
+ </div>
206
+ <div class="code-block">
207
+ <h3>POST /api/code</h3>
208
+ <p>Generate or modify code for various frameworks.</p>
209
+ <pre><code class="language-json">{
210
+ "framework": "React",
211
+ "task": "Create a login form component",
212
+ "code": "// Existing code (optional)"
213
+ }</code></pre>
214
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
215
+ </div>
216
+ <div class="code-block">
217
+ <h3>POST /api/analysis</h3>
218
+ <p>Analyze code or data with detailed insights.</p>
219
+ <pre><code class="language-json">{
220
+ "text": "Analyze this Python code: print('Hello World')"
221
+ }</code></pre>
222
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
223
+ </div>
224
+ <div class="code-block">
225
+ <h3>OAuth 2.0 Authentication</h3>
226
+ <p>Authenticate with MGZon using OAuth 2.0.</p>
227
+ <pre><code class="language-bash">curl -X POST https://hager-zon.vercel.app/oauth/token \
228
+ -H "Content-Type: application/json" \
229
+ -d '{"client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET", "grant_type": "client_credentials"}'</code></pre>
230
+ <button class="copy-btn" onclick="copyCode(this)">Copy</button>
231
+ </div>
232
+ </div>
233
+ <a href="/" class="btn">Back to Home</a>
234
+ </div>
235
+ <footer>
236
+ <div class="footer-container">
237
+ <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="footer-logo">
238
+ <p>Developed by <a href="https://mark-elasfar.web.app/" target="_blank">Mark Al-Asfar</a> | Powered by <a href="https://hager-zon.vercel.app/" target="_blank">MGZon AI</a></p>
239
+ <div class="footer-grid">
240
+ <div class="footer-card">
241
+ <i class="bx bx-mail-send"></i>
242
+ <h3>Email Us</h3>
243
+ <p>Contact: <a href="mailto:[email protected]">[email protected]</a></p>
244
+ </div>
245
+ <div class="footer-card">
246
+ <i class="bx bx-phone"></i>
247
+ <h3>Phone Support</h3>
248
+ <p>Call: +1-800-123-4567</p>
249
+ </div>
250
+ <div class="footer-card">
251
+ <i class="bx bx-group"></i>
252
+ <h3>Community</h3>
253
+ <p>Join: <a href="https://hager-zon.vercel.app/community">mgzon.com/community</a></p>
254
+ </div>
255
+ <div class="footer-card">
256
+ <i class="bx bx-code-alt"></i>
257
+ <h3>API Docs</h3>
258
+ <p>Explore: <a href="/docs">mgzon.com/docs</a></p>
259
+ </div>
260
+ <div class="footer-card">
261
+ <i class="bx bx-help-circle"></i>
262
+ <h3>FAQ</h3>
263
+ <p>Read: <a href="https://hager-zon.vercel.app/faq">mgzon.com/faq</a></p>
264
+ </div>
265
+ <div class="footer-card">
266
+ <i class="bx bx-book"></i>
267
+ <h3>Documentation</h3>
268
+ <p>Learn: <a href="/docs">mgzon.com/docs</a></p>
269
+ </div>
270
+ </div>
271
+ <div class="footer-social">
272
+ <a href="https://github.com/Mark-Lasfar/MGZon"><i class="bx bxl-github"></i></a>
273
+ <a href="https://x.com/MGZon"><i class="bx bxl-twitter"></i></a>
274
+ <a href="https://www.facebook.com/people/Mark-Al-Asfar/pfbid02GMisUQ8AqWkNZjoKtWFHH1tbdHuVscN1cjcFnZWy9HkRaAsmanBfT6mhySAyqpg4l/"><i class="bx bxl-facebook"></i></a>
275
+ </div>
276
+ <p>© 2025 Mark Al-Asfar & MGZon AI. All rights reserved.</p>
277
+ </div>
278
+ </footer>
279
+ <script src="/static/js/scripts.js"></script>
280
+ </body>
281
+ </html>
templates/index.html CHANGED
@@ -8,8 +8,17 @@
8
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css" rel="stylesheet">
9
  </head>
10
  <body>
 
 
 
 
 
 
 
 
 
 
11
  <div class="container">
12
- <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="logo">
13
  <h1>Welcome to MGZon Chatbot 🚀</h1>
14
  <p>
15
  MGZon Chatbot is your AI-powered assistant for code generation, analysis, and MGZon-specific queries. Built with Gradio and FastAPI, it supports multiple frameworks and languages. Ready to explore?
@@ -35,50 +44,26 @@
35
  </div>
36
  </div>
37
  </div>
38
- <div class="docs">
39
- <h2>API Documentation</h2>
40
- <p>Integrate MGZon Chatbot into your projects with our API. Supports Python, JavaScript, and more.</p>
41
- <div class="code-block">
42
- <h3>Python (gradio_client)</h3>
43
- <pre><code class="language-python">from gradio_client import Client
44
- client = Client("https://mgzon-mgzon-app.hf.space/gradio")
45
- result = client.predict(
46
- message="Generate a React component",
47
- system_prompt="You are a coding expert",
48
- temperature=0.7,
49
- max_new_tokens=4096,
50
- api_name="/api/chat"
51
- )
52
- print(result)</code></pre>
53
- <button class="copy-btn" onclick="copyCode(this)">Copy</button>
54
- </div>
55
- <div class="code-block">
56
- <h3>JavaScript (fetch)</h3>
57
- <pre><code class="language-javascript">fetch('https://mgzon-mgzon-app.hf.space/api/chat', {
58
- method: 'POST',
59
- headers: { 'Content-Type': 'application/json' },
60
- body: JSON.stringify({
61
- message: 'Generate a React component',
62
- system_prompt: 'You are a coding expert',
63
- temperature: 0.7,
64
- max_new_tokens: 4096
65
- })
66
- }).then(response => response.json()).then(data => console.log(data));</code></pre>
67
- <button class="copy-btn" onclick="copyCode(this)">Copy</button>
68
- </div>
69
- <div class="code-block">
70
- <h3>Bash (curl)</h3>
71
- <pre><code class="language-bash">curl -X POST https://mgzon-mgzon-app.hf.space/api/chat \
72
- -H "Content-Type: application/json" \
73
- -d '{"message":"Generate a React component","system_prompt":"You are a coding expert","temperature":0.7,"max_new_tokens":4096}'</code></pre>
74
- <button class="copy-btn" onclick="copyCode(this)">Copy</button>
75
  </div>
76
  </div>
77
  </div>
78
  <footer>
79
  <div class="footer-container">
80
  <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="footer-logo">
81
- <p>MGZon is a leading platform for e-commerce integrations and API solutions.</p>
82
  <div class="footer-grid">
83
  <div class="footer-card">
84
  <i class="bx bx-mail-send"></i>
@@ -93,22 +78,22 @@ print(result)</code></pre>
93
  <div class="footer-card">
94
  <i class="bx bx-group"></i>
95
  <h3>Community</h3>
96
- <p>Join: <a href="https://mgzon.com/community">mgzon.com/community</a></p>
97
  </div>
98
  <div class="footer-card">
99
  <i class="bx bx-code-alt"></i>
100
  <h3>API Docs</h3>
101
- <p>Explore: <a href="https://mgzon.com/developers">mgzon.com/developers</a></p>
102
  </div>
103
  <div class="footer-card">
104
  <i class="bx bx-help-circle"></i>
105
  <h3>FAQ</h3>
106
- <p>Read: <a href="https://mgzon.com/faq">mgzon.com/faq</a></p>
107
  </div>
108
  <div class="footer-card">
109
  <i class="bx bx-book"></i>
110
  <h3>Documentation</h3>
111
- <p>Learn: <a href="https://mgzon.com/docs">mgzon.com/docs</a></p>
112
  </div>
113
  </div>
114
  <div class="footer-social">
 
8
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css" rel="stylesheet">
9
  </head>
10
  <body>
11
+ <div class="sidebar">
12
+ <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="sidebar-logo">
13
+ <nav>
14
+ <a href="/" class="active">Home</a>
15
+ <a href="/docs">API Documentation</a>
16
+ <a href="https://hager-zon.vercel.app/about">About MGZon</a>
17
+ <a href="https://hager-zon.vercel.app/community">Community</a>
18
+ <a href="https://mark-elasfar.web.app/" target="_blank">Mark Al-Asfar</a>
19
+ </nav>
20
+ </div>
21
  <div class="container">
 
22
  <h1>Welcome to MGZon Chatbot 🚀</h1>
23
  <p>
24
  MGZon Chatbot is your AI-powered assistant for code generation, analysis, and MGZon-specific queries. Built with Gradio and FastAPI, it supports multiple frameworks and languages. Ready to explore?
 
44
  </div>
45
  </div>
46
  </div>
47
+ <div class="news">
48
+ <h2>Latest MGZon News</h2>
49
+ <div class="news-grid">
50
+ <div class="news-card">
51
+ <h3>New API Features</h3>
52
+ <p>Explore our updated API with OAuth 2.0 support.</p>
53
+ <a href="https://hager-zon.vercel.app/blog" target="_blank">Read More</a>
54
+ </div>
55
+ <div class="news-card">
56
+ <h3>Community Meetup</h3>
57
+ <p>Join our next virtual meetup on e-commerce trends.</p>
58
+ <a href="https://hager-zon.vercel.app/community" target="_blank">Join Now</a>
59
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  </div>
61
  </div>
62
  </div>
63
  <footer>
64
  <div class="footer-container">
65
  <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/main/public/icons/mg.svg" alt="MGZon Logo" class="footer-logo">
66
+ <p>Developed by <a href="https://mark-elasfar.web.app/" target="_blank">Mark Al-Asfar</a> | Powered by <a href="https://hager-zon.vercel.app/" target="_blank">MGZon AI</a></p>
67
  <div class="footer-grid">
68
  <div class="footer-card">
69
  <i class="bx bx-mail-send"></i>
 
78
  <div class="footer-card">
79
  <i class="bx bx-group"></i>
80
  <h3>Community</h3>
81
+ <p>Join: <a href="https://hager-zon.vercel.app/community">mgzon.com/community</a></p>
82
  </div>
83
  <div class="footer-card">
84
  <i class="bx bx-code-alt"></i>
85
  <h3>API Docs</h3>
86
+ <p>Explore: <a href="/docs">mgzon.com/docs</a></p>
87
  </div>
88
  <div class="footer-card">
89
  <i class="bx bx-help-circle"></i>
90
  <h3>FAQ</h3>
91
+ <p>Read: <a href="https://hager-zon.vercel.app/faq">mgzon.com/faq</a></p>
92
  </div>
93
  <div class="footer-card">
94
  <i class="bx bx-book"></i>
95
  <h3>Documentation</h3>
96
+ <p>Learn: <a href="/docs">mgzon.com/docs</a></p>
97
  </div>
98
  </div>
99
  <div class="footer-social">