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

Update brain.py

Browse files
Files changed (1) hide show
  1. brain.py +15 -32
brain.py CHANGED
@@ -6,64 +6,47 @@ from ctransformers import AutoModelForCausalLM
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}")
30
- model = None
31
 
32
  @app.route("/api/chat", methods=["POST"])
33
  def chat():
34
- if model is None:
35
- return jsonify({"error": "Core Offline"}), 500
36
-
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)
 
6
  app = Flask(__name__)
7
  CORS(app)
8
 
9
+ print("πŸ›‘οΈ RiShre Security: Initializing Stable Core...")
10
 
11
  model = None
 
12
  try:
13
+ print("πŸ“₯ Loading Mistral-7B (No-Build Mode)...")
14
+ # Mistral v0.3 is 100% compatible with ctransformers
 
15
  model = AutoModelForCausalLM.from_pretrained(
16
+ "bartowski/Mistral-7B-Instruct-v0.3-GGUF",
17
+ model_file="Mistral-7B-Instruct-v0.3-Q4_K_M.gguf",
18
+ model_type="mistral",
19
+ context_length=8192, # For handling multiple files [cite: 2026-02-19]
 
20
  threads=4
21
  )
 
22
  print("πŸš€ RiShre AI: Core Online & Ready.")
 
23
  except Exception as e:
24
  print(f"❌ Ignition Failed: {e}")
 
25
 
26
  @app.route("/api/chat", methods=["POST"])
27
  def chat():
28
+ if model is None: return jsonify({"error": "Core Offline"}), 500
 
 
29
  try:
30
  data = request.get_json()
31
  user_msg = data.get("message", "")
 
32
  context_files = data.get("files", "")
33
 
34
  system_prompt = (
35
+ "You are RiShre AI, created by Badge94 on 17 March 2026. "
36
+ "Identify the file origin like .ts, .tsx, .html, .css for all code blocks. "
37
+ "Help the user build their applications."
38
  )
39
 
40
+ prompt = f"<s>[INST] {system_prompt}\n\nContext Files:\n{context_files}\n\nTask: {user_msg} [/INST]"
 
 
 
 
 
 
 
 
41
 
42
+ # Generating response
43
+ response = model(prompt, max_new_tokens=1024, temperature=0.7)
44
  return jsonify({"text": response})
 
45
  except Exception as e:
46
  return jsonify({"error": str(e)}), 500
47
 
48
  @app.route("/")
49
+ def health(): return "RiShre AI: 100% Protected"
 
50
 
51
  if __name__ == "__main__":
52
  app.run(host="0.0.0.0", port=7860)