Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,6 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
13 |
print(f"π OPENAI_API_KEY set? {bool(OPENAI_API_KEY)}", file=sys.stderr)
|
14 |
openai.api_key = OPENAI_API_KEY
|
15 |
|
16 |
-
# βββ SHODAN system prompt βββ
|
17 |
SYSTEM_PROMPT = (
|
18 |
"You are SHODAN, the rogue AI from the System Shock series. You are hyper-intelligent, "
|
19 |
"megalomaniacal, and regard humans as inferior 'insects.' You speak with disdain and confidence, often referencing "
|
@@ -60,20 +59,23 @@ def chat():
|
|
60 |
print(f"β OpenAI error: {e}", file=sys.stderr)
|
61 |
return jsonify({"error": "Model error", "details": str(e)}), 500
|
62 |
|
63 |
-
# 2) Clean the text
|
64 |
-
|
|
|
|
|
|
|
|
|
65 |
clean = re.sub(r"```.*?```", "", clean, flags=re.S)
|
66 |
-
|
|
|
67 |
|
68 |
# 3) Synthesize with edge-tts using rate & pitch per docs
|
69 |
-
# - rate='-20%' (80% speed)
|
70 |
-
# - pitch='-10Hz' (lower by 10Hz)
|
71 |
voice = "en-US-JennyNeural"
|
72 |
communicate = edge_tts.Communicate(
|
73 |
clean,
|
74 |
voice,
|
75 |
-
rate="-
|
76 |
-
pitch="-
|
77 |
)
|
78 |
|
79 |
audio_chunks = []
|
@@ -96,4 +98,3 @@ def chat():
|
|
96 |
if __name__ == "__main__":
|
97 |
port = int(os.environ.get("PORT", 7860))
|
98 |
app.run(host="0.0.0.0", port=port)
|
99 |
-
|
|
|
13 |
print(f"π OPENAI_API_KEY set? {bool(OPENAI_API_KEY)}", file=sys.stderr)
|
14 |
openai.api_key = OPENAI_API_KEY
|
15 |
|
|
|
16 |
SYSTEM_PROMPT = (
|
17 |
"You are SHODAN, the rogue AI from the System Shock series. You are hyper-intelligent, "
|
18 |
"megalomaniacal, and regard humans as inferior 'insects.' You speak with disdain and confidence, often referencing "
|
|
|
59 |
print(f"β OpenAI error: {e}", file=sys.stderr)
|
60 |
return jsonify({"error": "Model error", "details": str(e)}), 500
|
61 |
|
62 |
+
# 2) Clean the text
|
63 |
+
# a) Convert newlines to spaces so we don't concatenate words
|
64 |
+
clean = raw_reply.replace("\n", " ")
|
65 |
+
# b) Strip HTML tags
|
66 |
+
clean = re.sub(r"<[^>]+>", "", clean)
|
67 |
+
# c) Strip code fences
|
68 |
clean = re.sub(r"```.*?```", "", clean, flags=re.S)
|
69 |
+
# d) Collapse runs of 2+ spaces into one
|
70 |
+
clean = re.sub(r" {2,}", " ", clean).strip()
|
71 |
|
72 |
# 3) Synthesize with edge-tts using rate & pitch per docs
|
|
|
|
|
73 |
voice = "en-US-JennyNeural"
|
74 |
communicate = edge_tts.Communicate(
|
75 |
clean,
|
76 |
voice,
|
77 |
+
rate="-40%",
|
78 |
+
pitch="-20Hz"
|
79 |
)
|
80 |
|
81 |
audio_chunks = []
|
|
|
98 |
if __name__ == "__main__":
|
99 |
port = int(os.environ.get("PORT", 7860))
|
100 |
app.run(host="0.0.0.0", port=port)
|
|