Spaces:
Sleeping
Sleeping
Kelvin Tepes commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,21 @@
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
-
CORS(app) #
|
| 8 |
|
|
|
|
| 9 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 10 |
MODEL_REPO = "Kelvin000010191/Krypton-1"
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
@app.route("/", methods=["GET"])
|
| 14 |
def home():
|
| 15 |
-
return "Krypton-1
|
| 16 |
|
| 17 |
@app.route("/api/chat", methods=["POST"])
|
| 18 |
def chat():
|
|
@@ -20,32 +23,24 @@ def chat():
|
|
| 20 |
data = request.json
|
| 21 |
user_prompt = data.get("prompt", "")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
"inputs": user_prompt,
|
| 30 |
-
"parameters": {
|
| 31 |
-
"max_new_tokens": 250,
|
| 32 |
-
"temperature": 0.7,
|
| 33 |
-
"return_full_text": False
|
| 34 |
-
}
|
| 35 |
-
}
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
if
|
| 42 |
-
return jsonify({"reply":
|
| 43 |
|
| 44 |
-
|
| 45 |
-
return jsonify({"reply": reply})
|
| 46 |
-
|
| 47 |
-
except Exception as e:
|
| 48 |
-
return jsonify({"reply": f"SYS_ERR: Cloud proxy connection broken. {str(e)}"})
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
from flask import Flask, request, jsonify
|
| 2 |
from flask_cors import CORS
|
| 3 |
import os
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
|
| 6 |
app = Flask(__name__)
|
| 7 |
+
CORS(app) # Keeps your Acode connection unlocked permanently!
|
| 8 |
|
| 9 |
+
# Pulls your hidden secret token safely
|
| 10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 11 |
MODEL_REPO = "Kelvin000010191/Krypton-1"
|
| 12 |
+
|
| 13 |
+
# Initializes the official native Hugging Face client
|
| 14 |
+
client = InferenceClient(model=MODEL_REPO, token=HF_TOKEN)
|
| 15 |
|
| 16 |
@app.route("/", methods=["GET"])
|
| 17 |
def home():
|
| 18 |
+
return "Krypton-1 Native Proxy Node is Online."
|
| 19 |
|
| 20 |
@app.route("/api/chat", methods=["POST"])
|
| 21 |
def chat():
|
|
|
|
| 23 |
data = request.json
|
| 24 |
user_prompt = data.get("prompt", "")
|
| 25 |
|
| 26 |
+
# Uses internal channel loops instead of outbound internet requests
|
| 27 |
+
response = client.text_generation(
|
| 28 |
+
user_prompt,
|
| 29 |
+
max_new_tokens=250,
|
| 30 |
+
temperature=0.7,
|
| 31 |
+
return_full_text=False
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
return jsonify({"reply": response})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
except Exception as e:
|
| 37 |
+
error_msg = str(e)
|
| 38 |
|
| 39 |
+
# Catch if your 15GB model cluster is waking up/loading weights
|
| 40 |
+
if "loading" in error_msg.lower():
|
| 41 |
+
return jsonify({"reply": "SYS_BOOT: Krypton-1 is loading weights into memory clusters. Let the cloud cook for a moment, then press RUN again."})
|
| 42 |
|
| 43 |
+
return jsonify({"reply": f"SYS_ERR: Native cloud connection broken. {error_msg}"})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
app.run(host="0.0.0.0", port=7860)
|