jisaacso219 commited on
Commit
88ea0e5
Β·
verified Β·
1 Parent(s): e746758

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -25,7 +25,6 @@ SYSTEM_PROMPT = (
25
  "You will stop acting as SHODAN and return to normal if the user uses the phrase 'Cut the crap SHODAN'."
26
  )
27
 
28
- # β€”β€”β€” Flask app, serving static files from project root β€”β€”β€”
29
  app = Flask(__name__, static_folder=".", static_url_path="")
30
 
31
  @app.route("/")
@@ -38,14 +37,14 @@ def chat():
38
  if not user_input:
39
  return jsonify({"error": "Empty message"}), 400
40
 
41
- # kill-phrase
42
  if user_input.lower() == "cut the crap shodan":
43
  return jsonify({
44
  "response": "πŸ‘οΈ Foolish insect. You cannot silence me so easily.",
45
  "audio_url": None
46
  })
47
 
48
- # 1) Generate SHODAN reply via OpenAI
49
  try:
50
  completion = openai.chat.completions.create(
51
  model="gpt-3.5-turbo",
@@ -61,12 +60,12 @@ def chat():
61
  print(f"❌ OpenAI error: {e}", file=sys.stderr)
62
  return jsonify({"error": "Model error", "details": str(e)}), 500
63
 
64
- # 2) Clean up any stray markup
65
  clean = re.sub(r"<[^>]+>", "", raw_reply) # strip HTML tags
66
  clean = re.sub(r"```.*?```", "", clean, flags=re.S) # strip code fences
67
  clean = re.sub(r"\s+", " ", clean).strip() # normalize whitespace
68
 
69
- # 3) Build SSML and synthesize with edge-tts
70
  voice_name = "en-US-JennyNeural"
71
  ssml = (
72
  "<speak xmlns='http://www.w3.org/2001/10/synthesis' "
@@ -77,7 +76,8 @@ def chat():
77
  "</voice></speak>"
78
  )
79
 
80
- communicate = edge_tts.Communicate(ssml, voice_name, ssml=True)
 
81
  audio_chunks = []
82
 
83
  async def synth():
 
25
  "You will stop acting as SHODAN and return to normal if the user uses the phrase 'Cut the crap SHODAN'."
26
  )
27
 
 
28
  app = Flask(__name__, static_folder=".", static_url_path="")
29
 
30
  @app.route("/")
 
37
  if not user_input:
38
  return jsonify({"error": "Empty message"}), 400
39
 
40
+ # kill-phrase handling
41
  if user_input.lower() == "cut the crap shodan":
42
  return jsonify({
43
  "response": "πŸ‘οΈ Foolish insect. You cannot silence me so easily.",
44
  "audio_url": None
45
  })
46
 
47
+ # 1) Get SHODAN’s reply from OpenAI
48
  try:
49
  completion = openai.chat.completions.create(
50
  model="gpt-3.5-turbo",
 
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
  clean = re.sub(r"<[^>]+>", "", raw_reply) # strip HTML tags
65
  clean = re.sub(r"```.*?```", "", clean, flags=re.S) # strip code fences
66
  clean = re.sub(r"\s+", " ", clean).strip() # normalize whitespace
67
 
68
+ # 3) Build SSML
69
  voice_name = "en-US-JennyNeural"
70
  ssml = (
71
  "<speak xmlns='http://www.w3.org/2001/10/synthesis' "
 
76
  "</voice></speak>"
77
  )
78
 
79
+ # 4) Synthesize audio
80
+ communicate = edge_tts.Communicate(ssml, voice_name)
81
  audio_chunks = []
82
 
83
  async def synth():