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