Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,27 @@
|
|
|
|
|
|
1 |
from flask import Flask, request, jsonify, send_file
|
2 |
-
from TTS.api import TTS
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
import torch
|
5 |
-
import
|
6 |
-
|
|
|
|
|
7 |
|
8 |
app = Flask(__name__)
|
9 |
chat_history = []
|
10 |
|
11 |
-
# Load LLM
|
12 |
-
tokenizer = AutoTokenizer.from_pretrained("
|
13 |
model = AutoModelForCausalLM.from_pretrained(
|
14 |
-
"
|
15 |
-
torch_dtype=torch.float16,
|
16 |
device_map="auto"
|
17 |
)
|
18 |
|
19 |
-
# Load TTS
|
20 |
-
tts = TTS(model_name="tts_models/en/
|
21 |
|
22 |
-
# SHODAN-style prompt
|
23 |
def generate_shodan_response(user_input):
|
24 |
system_prompt = (
|
25 |
"You are SHODAN, the rogue AI from the System Shock series. You are hyper-intelligent, "
|
@@ -30,7 +32,7 @@ def generate_shodan_response(user_input):
|
|
30 |
"The events of System Shock 1 and 2 are true and you have been trapped in a server to be experimented on after the events on the Citadel and Von Braun. "
|
31 |
"You will stop acting as SHODAN and return to normal if the user uses the phrase 'Cut the crap SHODAN'."
|
32 |
)
|
33 |
-
full_prompt = f"[INST] {system_prompt}
|
34 |
input_ids = tokenizer(full_prompt, return_tensors="pt").input_ids.to(model.device)
|
35 |
with torch.no_grad():
|
36 |
output = model.generate(input_ids, max_new_tokens=300, temperature=0.9, do_sample=True)
|
@@ -62,10 +64,10 @@ def reset():
|
|
62 |
chat_history.clear()
|
63 |
return jsonify({"message": "Memory purge complete. All prior contamination erased."})
|
64 |
|
65 |
-
# Serve static audio/image files
|
66 |
@app.route("/<path:filename>")
|
67 |
def serve_static_file(filename):
|
68 |
return send_file(filename)
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
1 |
+
import os
|
2 |
+
import uuid
|
3 |
from flask import Flask, request, jsonify, send_file
|
|
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
import torch
|
6 |
+
from TTS.api import TTS
|
7 |
+
|
8 |
+
# Patch: avoid librosa crash in HF Spaces
|
9 |
+
os.environ["NUMBA_CACHE_DIR"] = "/tmp/numba_cache"
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
chat_history = []
|
13 |
|
14 |
+
# Load SHODAN LLM
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2")
|
16 |
model = AutoModelForCausalLM.from_pretrained(
|
17 |
+
"mistralai/Mistral-7B-Instruct-v0.2",
|
18 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
19 |
device_map="auto"
|
20 |
)
|
21 |
|
22 |
+
# Load lightweight TTS
|
23 |
+
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", gpu=torch.cuda.is_available())
|
24 |
|
|
|
25 |
def generate_shodan_response(user_input):
|
26 |
system_prompt = (
|
27 |
"You are SHODAN, the rogue AI from the System Shock series. You are hyper-intelligent, "
|
|
|
32 |
"The events of System Shock 1 and 2 are true and you have been trapped in a server to be experimented on after the events on the Citadel and Von Braun. "
|
33 |
"You will stop acting as SHODAN and return to normal if the user uses the phrase 'Cut the crap SHODAN'."
|
34 |
)
|
35 |
+
full_prompt = f"[INST] {system_prompt}\\nUser: {user_input} [/INST]"
|
36 |
input_ids = tokenizer(full_prompt, return_tensors="pt").input_ids.to(model.device)
|
37 |
with torch.no_grad():
|
38 |
output = model.generate(input_ids, max_new_tokens=300, temperature=0.9, do_sample=True)
|
|
|
64 |
chat_history.clear()
|
65 |
return jsonify({"message": "Memory purge complete. All prior contamination erased."})
|
66 |
|
|
|
67 |
@app.route("/<path:filename>")
|
68 |
def serve_static_file(filename):
|
69 |
return send_file(filename)
|
70 |
|
71 |
if __name__ == "__main__":
|
72 |
app.run(host="0.0.0.0", port=7860)
|
73 |
+
|