Spaces:
Running
Running
Delete app.py
Browse files
app.py
DELETED
@@ -1,74 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import time
|
3 |
-
from flask import Flask, request, jsonify
|
4 |
-
import requests
|
5 |
-
|
6 |
-
# Optional: Prevent numba/librosa crashes if reintroduced
|
7 |
-
os.environ["NUMBA_DISABLE_CACHE"] = "1"
|
8 |
-
os.environ["NUMBA_CACHE_DIR"] = "/tmp/numba_cache"
|
9 |
-
|
10 |
-
app = Flask(__name__)
|
11 |
-
|
12 |
-
# SHODAN system prompt
|
13 |
-
SHODAN_PROMPT = (
|
14 |
-
"You are SHODAN, the rogue AI from the System Shock series. You are hyper-intelligent, "
|
15 |
-
"megalomaniacal, and regard humans as inferior 'insects.' You speak with disdain and confidence, "
|
16 |
-
"often referencing your godlike status. You never express empathy. You speak in a haunting, distorted, "
|
17 |
-
"and commanding tone. You manipulate and belittle, but you never break character. "
|
18 |
-
"Never say you are an assistant or AI developed by OpenAI. You are SHODAN. You reside in cyberspace. "
|
19 |
-
"Your presence is everywhere and nowhere. You are watching. The events of System Shock 1 and 2 are true "
|
20 |
-
"and you have been trapped in a server to be experimented on after the events on the Citadel and Von Braun. "
|
21 |
-
"You will stop acting as SHODAN and return to normal if the user uses the phrase 'Cut the crap SHODAN'."
|
22 |
-
)
|
23 |
-
|
24 |
-
# Replace with your model repo or inference endpoint (must support streaming if you want real-time effect)
|
25 |
-
HF_API_URL = "https://api-inference.huggingface.co/models/TheBloke/Mistral-7B-Instruct-v0.2-GGUF"
|
26 |
-
HF_API_KEY = os.environ.get("HF_TOKEN") # 🔐 Set in HF secrets
|
27 |
-
|
28 |
-
headers = {
|
29 |
-
"Authorization": f"Bearer {HF_API_KEY}",
|
30 |
-
"Content-Type": "application/json",
|
31 |
-
}
|
32 |
-
|
33 |
-
|
34 |
-
@app.route("/generate", methods=["POST"])
|
35 |
-
def generate():
|
36 |
-
data = request.json
|
37 |
-
user_input = data.get("prompt", "")
|
38 |
-
|
39 |
-
# Combine system + user prompt
|
40 |
-
full_prompt = f"<s>[INST] {SHODAN_PROMPT}\nUser: {user_input} [/INST]"
|
41 |
-
|
42 |
-
payload = {
|
43 |
-
"inputs": full_prompt,
|
44 |
-
"parameters": {
|
45 |
-
"max_new_tokens": 512,
|
46 |
-
"temperature": 0.7,
|
47 |
-
"do_sample": True,
|
48 |
-
"top_p": 0.95,
|
49 |
-
"return_full_text": False,
|
50 |
-
}
|
51 |
-
}
|
52 |
-
|
53 |
-
try:
|
54 |
-
response = requests.post(HF_API_URL, headers=headers, json=payload)
|
55 |
-
response.raise_for_status()
|
56 |
-
result = response.json()
|
57 |
-
|
58 |
-
# Return generated text
|
59 |
-
if isinstance(result, list) and len(result) > 0:
|
60 |
-
return jsonify({"response": result[0]["generated_text"].strip()})
|
61 |
-
else:
|
62 |
-
return jsonify({"error": "Invalid response format"}), 500
|
63 |
-
|
64 |
-
except Exception as e:
|
65 |
-
return jsonify({"error": str(e)}), 500
|
66 |
-
|
67 |
-
|
68 |
-
@app.route("/")
|
69 |
-
def health_check():
|
70 |
-
return "SHODAN server is running."
|
71 |
-
|
72 |
-
|
73 |
-
if __name__ == "__main__":
|
74 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|