MGZON commited on
Commit
2404de6
·
1 Parent(s): 0ecb31e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +118 -193
main.py CHANGED
@@ -18,8 +18,8 @@ class QueryRequest(BaseModel):
18
  message: str
19
  system_prompt: str = "You are a helpful assistant capable of code generation, analysis, review, and more."
20
  history: Optional[List[dict]] = None
21
- temperature: float = 0.7 # خفضت الـ temperature لردود أكثر دقة
22
- max_new_tokens: int = 4096 # قللت القيمة لتحسين الأداء
23
  enable_browsing: bool = False
24
 
25
  # تعريف LATEX_DELIMS
@@ -73,12 +73,14 @@ def web_search(query: str) -> str:
73
  google_api_key = os.getenv("GOOGLE_API_KEY")
74
  google_cse_id = os.getenv("GOOGLE_CSE_ID")
75
  if not google_api_key or not google_cse_id:
 
76
  return "Web search requires GOOGLE_API_KEY and GOOGLE_CSE_ID to be set."
77
  url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={google_cse_id}&q={query}+site:mgzon.com"
78
  response = requests.get(url, timeout=10)
79
  response.raise_for_status()
80
  results = response.json().get("items", [])
81
  if not results:
 
82
  return "No web results found."
83
  search_results = []
84
  for i, item in enumerate(results[:5]):
@@ -97,10 +99,10 @@ def web_search(query: str) -> str:
97
  search_results.append(f"Result {i+1}:\nTitle: {title}\nLink: {link}\nContent: {page_content}\n")
98
  return "\n".join(search_results)
99
  except Exception as e:
100
- logger.exception("Web search failed")
101
  return f"Web search error: {e}"
102
 
103
- # دالة request_generation
104
  @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
105
  def request_generation(
106
  api_key: str,
@@ -116,6 +118,7 @@ def request_generation(
116
  tool_choice: Optional[str] = None,
117
  deep_search: bool = False,
118
  ) -> Generator[str, None, None]:
 
119
  client = OpenAI(api_key=api_key, base_url=api_base, timeout=60.0)
120
  task_type = "general"
121
  if "code" in message.lower() or "programming" in message.lower() or any(ext in message.lower() for ext in ["python", "javascript", "react", "django", "flask"]):
@@ -151,6 +154,7 @@ def request_generation(
151
  tool_choice = tool_choice if tool_choice in ["auto", "none", "any", "required"] and "gpt-oss" in model_name else "none"
152
 
153
  try:
 
154
  stream = client.chat.completions.create(
155
  model=model_name,
156
  messages=input_messages,
@@ -225,6 +229,7 @@ def request_generation(
225
 
226
  if buffer:
227
  yield buffer
 
228
 
229
  except Exception as e:
230
  logger.exception(f"[Gateway] Streaming failed for model {model_name}: {e}")
@@ -282,6 +287,7 @@ def request_generation(
282
 
283
  if buffer:
284
  yield buffer
 
285
 
286
  except Exception as e2:
287
  logger.exception(f"[Gateway] Streaming failed for fallback model {fallback_model}: {e2}")
@@ -318,6 +324,8 @@ def request_generation(
318
  break
319
  if buffer:
320
  yield buffer
 
 
321
  except Exception as e3:
322
  logger.exception(f"[Gateway] Streaming failed for tertiary model {TERTIARY_MODEL_NAME}: {e3}")
323
  yield f"Error: Failed to load all models: {e3}"
@@ -513,16 +521,15 @@ async def root():
513
  <meta charset="utf-8">
514
  <meta name="viewport" content="width=device-width, initial-scale=1">
515
  <title>MGZon Chatbot - Powered by AI</title>
516
- <link href="https://unpkg.com/[email protected]/css/boxicons.min.css" rel="stylesheet">
517
  <style>
518
  :root {
519
  --primary-color: #1e3c72;
520
  --secondary-color: #2a5298;
521
  --accent-color: #ff6f61;
522
- --text-color: #ffffff;
523
- --card-bg: rgba(255, 255, 255, 0.1);
524
- --card-hover-bg: rgba(255, 255, 255, 0.2);
525
- --shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
526
  }
527
  body {
528
  font-family: 'Arial', sans-serif;
@@ -532,31 +539,31 @@ async def root():
532
  color: var(--text-color);
533
  display: flex;
534
  flex-direction: column;
 
535
  min-height: 100vh;
536
  overflow-x: hidden;
537
  }
538
  .container {
539
- max-width: 1200px;
540
- margin: auto;
541
- padding: 40px 20px;
542
  text-align: center;
543
- background: var(--card-bg);
 
544
  border-radius: 15px;
545
- box-shadow: var(--shadow);
546
  backdrop-filter: blur(10px);
 
547
  }
548
  h1 {
549
  font-size: 3.5rem;
550
  margin-bottom: 20px;
551
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
552
- animation: fadeIn 1s ease-in-out;
553
  }
554
  p {
555
  font-size: 1.2rem;
556
  line-height: 1.6;
557
  margin-bottom: 30px;
558
  }
559
- a#chatbot-link {
560
  display: inline-block;
561
  padding: 15px 40px;
562
  background: var(--accent-color);
@@ -564,9 +571,10 @@ async def root():
564
  text-decoration: none;
565
  border-radius: 25px;
566
  font-size: 1.2rem;
 
567
  transition: background 0.3s, transform 0.2s;
568
  }
569
- a#chatbot-link:hover {
570
  background: #e55a50;
571
  transform: scale(1.05);
572
  }
@@ -576,109 +584,89 @@ async def root():
576
  }
577
  .features h2, .integration h2 {
578
  font-size: 2rem;
579
- margin-bottom: 15px;
580
- color: var(--text-color);
581
  }
582
  .features ul {
583
- background: var(--card-bg);
 
 
584
  padding: 20px;
585
  border-radius: 10px;
586
- list-style: none;
587
  }
588
  .features li {
589
- margin-bottom: 10px;
590
  font-size: 1.1rem;
591
  display: flex;
592
  align-items: center;
593
- gap: 10px;
 
 
 
594
  }
595
  .integration pre {
596
- background: var(--card-bg);
597
  padding: 20px;
598
  border-radius: 10px;
599
  font-family: 'Courier New', monospace;
600
  color: #c9e4ca;
601
- white-space: pre-wrap;
602
- font-size: 0.95rem;
603
  }
604
  .footer {
605
- background: linear-gradient(270deg, #1f2937, #111827, #1f2937);
606
- background-size: 200% 200%;
607
- animation: gradient 15s ease infinite;
608
- padding: 40px 20px;
609
- margin-top: auto;
610
  text-align: center;
611
- }
612
- @keyframes gradient {
613
- 0% { background-position: 0% 50%; }
614
- 50% { background-position: 100% 50%; }
615
- 100% { background-position: 0% 50%; }
616
- }
617
- .footer-card {
618
- background: var(--card-bg);
619
  padding: 20px;
620
- border-radius: 10px;
621
- box-shadow: var(--shadow);
622
- transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
623
- }
624
- .footer-card:hover {
625
- transform: scale(1.05);
626
- background: var(--card-hover-bg);
627
- box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
628
- }
629
- .modal {
630
- display: none;
631
- position: fixed;
632
- z-index: 1000;
633
- left: 0;
634
- top: 0;
635
- width: 100%;
636
- height: 100%;
637
  background: rgba(0, 0, 0, 0.5);
638
- align-items: center;
639
- justify-content: center;
640
  }
641
- .modal-content {
642
- background: #fff;
643
- padding: 20px;
644
- border-radius: 10px;
645
- max-width: 600px;
646
- width: 90%;
647
- color: #333;
648
  }
649
- .close-btn {
650
- float: right;
651
- font-size: 1.5rem;
652
- cursor: pointer;
653
  }
654
  @keyframes fadeIn {
655
  from { opacity: 0; transform: translateY(20px); }
656
  to { opacity: 1; transform: translateY(0); }
657
  }
658
- .container > *, .footer > * {
659
  animation: fadeIn 0.5s ease-in-out;
660
  }
 
 
 
 
 
 
 
 
 
661
  </style>
662
  </head>
663
  <body>
664
  <div class="container">
665
  <h1>Welcome to MGZon Chatbot 🚀</h1>
666
  <p>
667
- 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?
668
  </p>
669
- <a href="/gradio" id="chatbot-link">Launch Chatbot</a>
670
  <div class="features">
671
  <h2>Features</h2>
672
  <ul>
673
- <li><i class='bx bx-code-alt'></i> Generate code for React, Django, Flask, and more.</li>
674
- <li><i class='bx bx-analyse'></i> Analyze and review code or data with detailed insights.</li>
675
- <li><i class='bx bx-globe'></i> Web search integration for MGZon-related queries.</li>
676
- <li><i class='bx bx-bot'></i> Powered by GPT-OSS-20B and fine-tuned MGZon/Veltrix model.</li>
 
677
  </ul>
678
  </div>
679
  <div class="integration">
680
  <h2>Integrate with MGZon Chatbot</h2>
681
- <p>Our API supports integration with various projects, frameworks (React, Django, Flask), and languages (Python, JavaScript, etc.). Below are examples to get started:</p>
 
 
682
  <pre>
683
  # Python Example (using gradio_client)
684
  from gradio_client import Client
@@ -704,131 +692,68 @@ fetch('https://mgzon-mgzon-app.hf.space/api/chat', {
704
  })
705
  }).then(response => response.json()).then(data => console.log(data));
706
 
707
- # Bash Example (using curl)
708
  curl -X POST https://mgzon-mgzon-app.hf.space/api/chat \
709
  -H "Content-Type: application/json" \
710
- -d '{"message":"Generate a Django model for an e-commerce product","system_prompt":"You are a coding expert","temperature":0.7,"max_new_tokens":4096}'
711
-
712
- # Ruby Example
713
- require 'httparty'
714
- response = HTTParty.post('https://mgzon-mgzon-app.hf.space/api/chat',
715
- headers: { 'Content-Type' => 'application/json' },
716
- body: {
717
- message: 'Generate a Ruby on Rails controller for user management',
718
- system_prompt: 'You are a coding expert',
719
- temperature: 0.7,
720
- max_new_tokens: 4096
721
- }.to_json
722
- )
723
- puts response.parsed_response
724
-
725
- # PHP Example
726
- <?php
727
- $ch = curl_init('https://mgzon-mgzon-app.hf.space/api/chat');
728
- curl_setopt($ch, CURLOPT_POST, true);
729
- curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
730
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
731
- 'message' => 'Generate a Laravel route for API authentication',
732
- 'system_prompt' => 'You are a coding expert',
733
- 'temperature' => 0.7,
734
- 'max_new_tokens' => 4096
735
- ]));
736
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
737
- $response = curl_exec($ch);
738
- curl_close($ch);
739
- echo $response;
740
- ?>
 
 
 
 
 
 
 
 
 
 
 
741
  </pre>
742
- <p>Check out our full <a href="https://mgzon.com/docs" target="_blank">API Documentation</a> for more details on endpoints, parameters, and authentication (OAuth 2.0).</p>
743
  </div>
744
  </div>
745
  <footer class="footer">
746
- <div class="container">
747
- <img src="https://raw.githubusercontent.com/Mark-Lasfar/MGZon/9a1b2149507ae61fec3bb7fb86d8d16c11852f3b/public/icons/mg.svg" alt="MGZon Logo" class="w-24 h-24 mx-auto mb-4">
748
- <p class="text-gray-300 max-w-2xl mx-auto text-lg">MGZon is a leading platform for e-commerce integrations and API solutions.</p>
749
- <h3 class="text-3xl font-bold mb-8 text-center">Contact Information</h3>
750
- <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
751
- <div class="footer-card" data-details="Reach our support team at support@mgzon.com. We aim to respond within 24 hours.">
752
- <div class="flex justify-center mb-4"><i class='bx bx-mail-send text-4xl text-blue-400'></i></div>
753
- <h4 class="text-xl font-semibold text-center">Email Us</h4>
754
- <p class="text-gray-300 text-center mt-2">Reach out to our support team via email.</p>
755
- </div>
756
- <div class="footer-card" data-details="Call +1-800-123-4567 for immediate support (Monday-Friday, 9 AM-5 PM EST).">
757
- <div class="flex justify-center mb-4"><i class='bx bx-phone text-4xl text-blue-400'></i></div>
758
- <h4 class="text-xl font-semibold text-center">Phone Support</h4>
759
- <p class="text-gray-300 text-center mt-2">Call us for immediate assistance.</p>
760
- </div>
761
- <div class="footer-card" data-details="Support available Monday-Friday, 9 AM-5 PM EST. Enterprise clients can request 24/7 support.">
762
- <div class="flex justify-center mb-4"><i class='bx bx-group text-4xl text-blue-400'></i></div>
763
- <h4 class="text-xl font-semibold text-center">Support Hours</h4>
764
- <p class="text-gray-300 text-center mt-2">Available 9 AM - 5 PM, Monday to Friday.</p>
765
- </div>
766
- </div>
767
- <h3 class="text-3xl font-bold mb-8 text-center">Resources</h3>
768
- <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
769
- <div class="footer-card" data-details="Explore API endpoints, OAuth 2.0, and integration guides at mgzon.com/developers.">
770
- <div class="flex justify-center mb-4"><i class='bx bx-code-alt text-4xl text-green-400'></i></div>
771
- <h4 class="text-xl font-semibold text-center">API Documentation</h4>
772
- <p class="text-gray-300 text-center mt-2">Explore our API endpoints and integration guides.</p>
773
- </div>
774
- <div class="footer-card" data-details="Find answers to common questions at mgzon.com/community.">
775
- <div class="flex justify-center mb-4"><i class='bx bx-help-circle text-4xl text-green-400'></i></div>
776
- <h4 class="text-xl font-semibold text-center">FAQ</h4>
777
- <p class="text-gray-300 text-center mt-2">Find answers to common questions.</p>
778
- </div>
779
- <div class="footer-card" data-details="Step-by-step guides on using MGZon at mgzon.com/docs.">
780
- <div class="flex justify-center mb-4"><i class='bx bx-book text-4xl text-green-400'></i></div>
781
- <h4 class="text-xl font-semibold text-center">Documentation</h4>
782
- <p class="text-gray-300 text-center mt-2">Learn how to use MGZon with our detailed guides.</p>
783
- </div>
784
- </div>
785
- <div class="mt-12 text-center">
786
- <div class="flex justify-center space-x-6 mb-6">
787
- <a href="https://github.com/Mark-Lasfar/MGZon" class="text-gray-300 hover:text-blue-400"><i class='bx bxl-github text-3xl'></i></a>
788
- <a href="https://x.com/MGZon" class="text-gray-300 hover:text-blue-400"><i class='bx bxl-twitter text-3xl'></i></a>
789
- <a href="https://www.facebook.com/people/Mark-Al-Asfar/pfbid02GMisUQ8AqWkNZjoKtWFHH1tbdHuVscN1cjcFnZWy9HkRaAsmanBfT6mhySAyqpg4l/" class="text-gray-300 hover:text-blue-400"><i class='bx bxl-facebook text-3xl'></i></a>
790
- </div>
791
- <p class="text-gray-300">© 2025 Mark Al-Asfar & MGZon AI. All rights reserved.</p>
792
- </div>
793
- </div>
794
- <div id="footer-modal" class="modal">
795
- <div class="modal-content">
796
- <span id="close-btn" class="close-btn">&times;</span>
797
- <h3 id="modal-title" class="text-2xl font-bold mb-4"></h3>
798
- <p id="modal-details" class="text-gray-700"></p>
799
- </div>
800
- </div>
801
  </footer>
802
  <script>
803
- // Modal functionality
804
- const modal = document.getElementById('footer-modal');
805
- const modalTitle = document.getElementById('modal-title');
806
- const modalDetails = document.getElementById('modal-details');
807
- const closeBtn = document.getElementById('close-btn');
808
- const cards = document.querySelectorAll('.footer-card');
809
-
810
- cards.forEach(card => {
811
- card.addEventListener('click', () => {
812
- modalTitle.textContent = card.querySelector('h4').textContent;
813
- modalDetails.textContent = card.getAttribute('data-details');
814
- modal.style.display = 'flex';
815
- });
816
- });
817
-
818
- closeBtn.addEventListener('click', () => {
819
- modal.style.display = 'none';
820
- });
821
-
822
- window.addEventListener('click', (e) => {
823
- if (e.target === modal) {
824
- modal.style.display = 'none';
825
- }
826
- });
827
-
828
- // Redirect to /gradio with proper URL
829
- document.getElementById('chatbot-link').addEventListener('click', (e) => {
830
  e.preventDefault();
831
- window.location.href = 'https://mgzon-mgzon-app.hf.space/gradio';
832
  });
833
  </script>
834
  </body>
 
18
  message: str
19
  system_prompt: str = "You are a helpful assistant capable of code generation, analysis, review, and more."
20
  history: Optional[List[dict]] = None
21
+ temperature: float = 0.7 # خفضنا الـ temperature عشان ردود أكثر دقة
22
+ max_new_tokens: int = 4096 # قللنا العدد عشان نضمن ردود مكتملة
23
  enable_browsing: bool = False
24
 
25
  # تعريف LATEX_DELIMS
 
73
  google_api_key = os.getenv("GOOGLE_API_KEY")
74
  google_cse_id = os.getenv("GOOGLE_CSE_ID")
75
  if not google_api_key or not google_cse_id:
76
+ logger.warning("GOOGLE_API_KEY or GOOGLE_CSE_ID not set, web search disabled.")
77
  return "Web search requires GOOGLE_API_KEY and GOOGLE_CSE_ID to be set."
78
  url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={google_cse_id}&q={query}+site:mgzon.com"
79
  response = requests.get(url, timeout=10)
80
  response.raise_for_status()
81
  results = response.json().get("items", [])
82
  if not results:
83
+ logger.info("No web results found for query: %s", query)
84
  return "No web results found."
85
  search_results = []
86
  for i, item in enumerate(results[:5]):
 
99
  search_results.append(f"Result {i+1}:\nTitle: {title}\nLink: {link}\nContent: {page_content}\n")
100
  return "\n".join(search_results)
101
  except Exception as e:
102
+ logger.exception("Web search failed for query: %s", query)
103
  return f"Web search error: {e}"
104
 
105
+ # دالة request_generation مع logging إضافي
106
  @retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
107
  def request_generation(
108
  api_key: str,
 
118
  tool_choice: Optional[str] = None,
119
  deep_search: bool = False,
120
  ) -> Generator[str, None, None]:
121
+ logger.info(f"Requesting generation for model: {model_name}, endpoint: {api_base}, message: {message}")
122
  client = OpenAI(api_key=api_key, base_url=api_base, timeout=60.0)
123
  task_type = "general"
124
  if "code" in message.lower() or "programming" in message.lower() or any(ext in message.lower() for ext in ["python", "javascript", "react", "django", "flask"]):
 
154
  tool_choice = tool_choice if tool_choice in ["auto", "none", "any", "required"] and "gpt-oss" in model_name else "none"
155
 
156
  try:
157
+ logger.debug(f"Sending request to {api_base} with model {model_name}")
158
  stream = client.chat.completions.create(
159
  model=model_name,
160
  messages=input_messages,
 
229
 
230
  if buffer:
231
  yield buffer
232
+ logger.info(f"Generation completed successfully for model: {model_name}")
233
 
234
  except Exception as e:
235
  logger.exception(f"[Gateway] Streaming failed for model {model_name}: {e}")
 
287
 
288
  if buffer:
289
  yield buffer
290
+ logger.info(f"Fallback generation completed successfully for model: {fallback_model}")
291
 
292
  except Exception as e2:
293
  logger.exception(f"[Gateway] Streaming failed for fallback model {fallback_model}: {e2}")
 
324
  break
325
  if buffer:
326
  yield buffer
327
+ logger.info(f"Tertiary generation completed successfully for model: {TERTIARY_MODEL_NAME}")
328
+
329
  except Exception as e3:
330
  logger.exception(f"[Gateway] Streaming failed for tertiary model {TERTIARY_MODEL_NAME}: {e3}")
331
  yield f"Error: Failed to load all models: {e3}"
 
521
  <meta charset="utf-8">
522
  <meta name="viewport" content="width=device-width, initial-scale=1">
523
  <title>MGZon Chatbot - Powered by AI</title>
524
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/css/boxicons.min.css" rel="stylesheet">
525
  <style>
526
  :root {
527
  --primary-color: #1e3c72;
528
  --secondary-color: #2a5298;
529
  --accent-color: #ff6f61;
530
+ --text-color: #fff;
531
+ --container-bg: rgba(255, 255, 255, 0.1);
532
+ --container-border: rgba(255, 255, 255, 0.2);
 
533
  }
534
  body {
535
  font-family: 'Arial', sans-serif;
 
539
  color: var(--text-color);
540
  display: flex;
541
  flex-direction: column;
542
+ align-items: center;
543
  min-height: 100vh;
544
  overflow-x: hidden;
545
  }
546
  .container {
547
+ max-width: 900px;
 
 
548
  text-align: center;
549
+ padding: 40px;
550
+ background: var(--container-bg);
551
  border-radius: 15px;
552
+ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
553
  backdrop-filter: blur(10px);
554
+ margin: 20px;
555
  }
556
  h1 {
557
  font-size: 3.5rem;
558
  margin-bottom: 20px;
559
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
 
560
  }
561
  p {
562
  font-size: 1.2rem;
563
  line-height: 1.6;
564
  margin-bottom: 30px;
565
  }
566
+ a.cta-button {
567
  display: inline-block;
568
  padding: 15px 40px;
569
  background: var(--accent-color);
 
571
  text-decoration: none;
572
  border-radius: 25px;
573
  font-size: 1.2rem;
574
+ font-weight: bold;
575
  transition: background 0.3s, transform 0.2s;
576
  }
577
+ a.cta-button:hover {
578
  background: #e55a50;
579
  transform: scale(1.05);
580
  }
 
584
  }
585
  .features h2, .integration h2 {
586
  font-size: 2rem;
587
+ margin-bottom: 20px;
588
+ text-align: center;
589
  }
590
  .features ul {
591
+ list-style: none;
592
+ padding: 0;
593
+ background: rgba(0, 0, 0, 0.2);
594
  padding: 20px;
595
  border-radius: 10px;
 
596
  }
597
  .features li {
598
+ margin-bottom: 15px;
599
  font-size: 1.1rem;
600
  display: flex;
601
  align-items: center;
602
+ }
603
+ .features li::before {
604
+ content: '🚀';
605
+ margin-right: 10px;
606
  }
607
  .integration pre {
608
+ background: rgba(0, 0, 0, 0.3);
609
  padding: 20px;
610
  border-radius: 10px;
611
  font-family: 'Courier New', monospace;
612
  color: #c9e4ca;
613
+ overflow-x: auto;
 
614
  }
615
  .footer {
 
 
 
 
 
616
  text-align: center;
 
 
 
 
 
 
 
 
617
  padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
618
  background: rgba(0, 0, 0, 0.5);
619
+ width: 100%;
620
+ margin-top: 40px;
621
  }
622
+ .footer a {
623
+ color: var(--accent-color);
624
+ text-decoration: none;
625
+ margin: 0 10px;
 
 
 
626
  }
627
+ .footer a:hover {
628
+ text-decoration: underline;
 
 
629
  }
630
  @keyframes fadeIn {
631
  from { opacity: 0; transform: translateY(20px); }
632
  to { opacity: 1; transform: translateY(0); }
633
  }
634
+ .container > * {
635
  animation: fadeIn 0.5s ease-in-out;
636
  }
637
+ @keyframes gradient {
638
+ 0% { background-position: 0% 50%; }
639
+ 50% { background-position: 100% 50%; }
640
+ 100% { background-position: 0% 50%; }
641
+ }
642
+ body {
643
+ background-size: 200% 200%;
644
+ animation: gradient 15s ease infinite;
645
+ }
646
  </style>
647
  </head>
648
  <body>
649
  <div class="container">
650
  <h1>Welcome to MGZon Chatbot 🚀</h1>
651
  <p>
652
+ MGZon Chatbot is your AI-powered assistant for code generation, analysis, and MGZon-specific queries. Built with Gradio and FastAPI, it supports multiple frameworks (React, Django, Flask) and languages (Python, JavaScript, and more). Ready to revolutionize your projects?
653
  </p>
654
+ <a href="/gradio" class="cta-button">Launch Chatbot</a>
655
  <div class="features">
656
  <h2>Features</h2>
657
  <ul>
658
+ <li>💻 Generate clean, well-commented code for React, Django, Flask, and more.</li>
659
+ <li>🔍 Analyze code or data with step-by-step reasoning and insights.</li>
660
+ <li>🌐 Web search integration for real-time MGZon-related information.</li>
661
+ <li>🤖 Powered by GPT-OSS-20B and fine-tuned MGZon/Veltrix model.</li>
662
+ <li>📝 Review and improve your code with detailed suggestions.</li>
663
  </ul>
664
  </div>
665
  <div class="integration">
666
  <h2>Integrate with MGZon Chatbot</h2>
667
+ <p>
668
+ Integrate our API into your projects with ease. Below are examples for Python, JavaScript, and cURL, supporting frameworks like React, Django, Flask, and more. Use it for web apps, mobile apps, or CLI tools.
669
+ </p>
670
  <pre>
671
  # Python Example (using gradio_client)
672
  from gradio_client import Client
 
692
  })
693
  }).then(response => response.json()).then(data => console.log(data));
694
 
695
+ // Bash Example (using cURL)
696
  curl -X POST https://mgzon-mgzon-app.hf.space/api/chat \
697
  -H "Content-Type: application/json" \
698
+ -d '{"message":"Analyze the performance of a Django REST API","system_prompt":"You are an expert analyst","temperature":0.7,"max_new_tokens":4096}'
699
+
700
+ # Django Integration Example
701
+ # Add to your Django views.py
702
+ import requests
703
+ def chatbot_view(request):
704
+ response = requests.post(
705
+ 'https://mgzon-mgzon-app.hf.space/api/chat',
706
+ json={
707
+ 'message': 'Create a Django model for an e-commerce product',
708
+ 'system_prompt': 'You are a Django expert',
709
+ 'temperature': 0.7,
710
+ 'max_new_tokens': 4096
711
+ }
712
+ )
713
+ return HttpResponse(response.json()['response'])
714
+
715
+ # React Integration Example
716
+ import React, { useState } from 'react';
717
+ function ChatbotComponent() {
718
+ const [response, setResponse] = useState('');
719
+ const fetchResponse = async () => {
720
+ const res = await fetch('https://mgzon-mgzon-app.hf.space/api/chat', {
721
+ method: 'POST',
722
+ headers: { 'Content-Type': 'application/json' },
723
+ body: JSON.stringify({
724
+ message: 'Generate a React component for a dashboard',
725
+ system_prompt: 'You are a React expert',
726
+ temperature: 0.7,
727
+ max_new_tokens: 4096
728
+ })
729
+ });
730
+ const data = await res.json();
731
+ setResponse(data.response);
732
+ };
733
+ return (
734
+ <div>
735
+ <button onClick={fetchResponse}>Generate Code</button>
736
+ <pre>{response}</pre>
737
+ </div>
738
+ );
739
+ }
740
  </pre>
 
741
  </div>
742
  </div>
743
  <footer class="footer">
744
+ <p>© 2025 MGZon AI. All rights reserved.</p>
745
+ <p>
746
+ <a href="https://mgzon.com/about">About</a> |
747
+ <a href="https://mgzon.com/support">Support</a> |
748
+ <a href="https://mgzon.com/docs">Documentation</a> |
749
+ <a href="https://github.com/Mark-Lasfar/MGZon">GitHub</a>
750
+ </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
751
  </footer>
752
  <script>
753
+ // إصلاح الـ redirect
754
+ document.querySelector('.cta-button').addEventListener('click', (e) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
  e.preventDefault();
756
+ window.location.href = window.location.origin + '/gradio/';
757
  });
758
  </script>
759
  </body>