rexprimematrix commited on
Commit
ee5e1cb
Β·
verified Β·
1 Parent(s): 1d70359

Update brain.py

Browse files
Files changed (1) hide show
  1. brain.py +26 -46
brain.py CHANGED
@@ -1,32 +1,29 @@
1
  import os
2
- import json
3
  from flask import Flask, request, jsonify
4
  from flask_cors import CORS
5
- from llama_cpp import Llama
6
- from huggingface_hub import hf_hub_download
7
 
8
  app = Flask(__name__)
9
  CORS(app)
10
 
11
- print("πŸ›‘οΈ RiShre Studio: Initializing Stable Qwen Core...")
12
 
13
- # Model Config: Qwen-2.5-Coder-7B-Instruct
14
- model_repo = "Qwen/Qwen2.5-Coder-7B-Instruct-GGUF"
15
- model_file = "qwen2.5-coder-7b-instruct-q4_k_m.gguf"
16
  model = None
17
 
18
  try:
19
- print("πŸ“₯ Downloading Qwen Engine (Bypassing wheel build)...")
20
- model_path = hf_hub_download(repo_id=model_repo, filename=model_file)
21
-
22
- print("🧠 Loading 16k Context Memory for 10-File Handling...")
23
- model = Llama(
24
- model_path=model_path,
25
- n_ctx=16384, # High memory for complex project files
26
- n_threads=4, # Safe for HF Free Tier
27
- n_batch=512
 
28
  )
29
- print("πŸš€ RiShre Studio: Engine Online & 100% Protected.")
 
30
 
31
  except Exception as e:
32
  print(f"❌ Ignition Failed: {e}")
@@ -40,50 +37,33 @@ def chat():
40
  try:
41
  data = request.get_json()
42
  user_msg = data.get("message", "")
43
- # Frontend will send the code files here
44
- context_files = data.get("files", "No files uploaded yet.")
45
 
46
- # πŸ›‘οΈ THE MASTER IDENTITY & JSON PROMPT
47
  system_prompt = (
48
- "You are 'RiShre Studio Engine', an Elite Full-Stack Developer created by Rishav (Badge94) on 17 March 2026. "
49
- "Your identity is RiShre AI. You focus on 100% Security. "
50
- "STRICT OUTPUT RULE: Always respond in valid JSON format with exactly two keys: "
51
- "1. 'logic': A detailed explanation of what to change and why (Dependencies). "
52
- "2. 'files': An array of objects, each containing 'filename', 'extension' (e.g. .tsx, .py, .html), and 'code'. "
53
- "Do not output any markdown formatting or extra text outside the JSON."
54
  )
55
 
56
- # Qwen-2.5 ChatML Format
57
- prompt = f"<|im_start|>system\n{system_prompt}\n<|im_end|>\n"
58
- prompt += f"<|im_start|>user\nHere are the current project files:\n{context_files}\n\nTask: {user_msg}\n<|im_end|>\n"
59
- prompt += f"<|im_start|>assistant\n"
60
 
61
  response = model(
62
  prompt,
63
- max_tokens=2048,
64
- temperature=0.2, # Extremely low for precise coding
65
- stop=["<|im_end|>"]
66
  )
67
 
68
- raw_text = response["choices"][0]["text"].strip()
69
-
70
- # Parse JSON before sending to React frontend
71
- try:
72
- parsed_json = json.loads(raw_text)
73
- return jsonify(parsed_json)
74
- except:
75
- # Fallback format if AI makes a tiny mistake in JSON
76
- return jsonify({
77
- "logic": raw_text,
78
- "files": []
79
- })
80
 
81
  except Exception as e:
82
  return jsonify({"error": str(e)}), 500
83
 
84
  @app.route("/")
85
  def health():
86
- return "RiShre Engine: Status 100% Protected"
87
 
88
  if __name__ == "__main__":
89
  app.run(host="0.0.0.0", port=7860)
 
1
  import os
 
2
  from flask import Flask, request, jsonify
3
  from flask_cors import CORS
4
+ from ctransformers import AutoModelForCausalLM
 
5
 
6
  app = Flask(__name__)
7
  CORS(app)
8
 
9
+ print("πŸ›‘οΈ RiShre Security: Initializing Fast Studio Core...")
10
 
 
 
 
11
  model = None
12
 
13
  try:
14
+ print("πŸ“₯ Loading Qwen-Coder via CTransformers (No-Build Mode)...")
15
+
16
+ # Hum Mistral ki jagah Qwen-2.5-Coder use karenge kyunki wo 10 files ke liye best hai [cite: 2026-03-01]
17
+ model = AutoModelForCausalLM.from_pretrained(
18
+ "Qwen/Qwen2.5-Coder-7B-Instruct-GGUF",
19
+ model_file="qwen2.5-coder-7b-instruct-q4_k_m.gguf",
20
+ model_type="gpt2", # Qwen ke liye gpt2 best chalta hai [cite: 2026-02-19]
21
+ gpu_layers=0, # CPU only
22
+ context_length=8192, # 10 files handle karne ke liye [cite: 2026-02-19]
23
+ threads=4
24
  )
25
+
26
+ print("πŸš€ RiShre AI: Core Online & Ready.")
27
 
28
  except Exception as e:
29
  print(f"❌ Ignition Failed: {e}")
 
37
  try:
38
  data = request.get_json()
39
  user_msg = data.get("message", "")
40
+ # Frontend se files ka context bhi aayega yahan [cite: 2026-03-01]
41
+ context_files = data.get("files", "")
42
 
 
43
  system_prompt = (
44
+ "You are RiShre AI, an elite coder created by Badge94 on 17 March 2026. "
45
+ "Identify the file extension like .tsx, .html, .py for every code block. "
46
+ "Think about cross-file dependencies."
 
 
 
47
  )
48
 
49
+ # Chat format for Qwen
50
+ prompt = f"System: {system_prompt}\nContext: {context_files}\nUser: {user_msg}\nAssistant:"
 
 
51
 
52
  response = model(
53
  prompt,
54
+ max_new_tokens=1024,
55
+ temperature=0.3,
56
+ top_p=0.9
57
  )
58
 
59
+ return jsonify({"text": response})
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  except Exception as e:
62
  return jsonify({"error": str(e)}), 500
63
 
64
  @app.route("/")
65
  def health():
66
+ return "RiShre AI: Status 100% Protected"
67
 
68
  if __name__ == "__main__":
69
  app.run(host="0.0.0.0", port=7860)