jisaacso219 commited on
Commit
5ef315e
Β·
verified Β·
1 Parent(s): 609b0e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
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 (strip tags/fences, preserve spaces)
64
- clean = re.sub(r"<[^>]+>", "", raw_reply)
 
 
 
 
65
  clean = re.sub(r"```.*?```", "", clean, flags=re.S)
66
- clean = clean.strip()
 
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="-20%",
76
- pitch="-10Hz"
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)