Dreamy0 commited on
Commit
92ff2f7
·
verified ·
1 Parent(s): 5737b10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -30
app.py CHANGED
@@ -1,33 +1,11 @@
1
- from flask import Flask, request, jsonify, send_from_directory
2
  from flask_cors import CORS
3
- import os
4
  import requests
5
  import random
6
 
7
- # Serve UI from / (but static files live in 'ui/')
8
- app = Flask(__name__, static_folder='ui', static_url_path='/')
9
  CORS(app, resources={r"/*": {"origins": "*"}})
10
 
11
- # ---------- UI ----------
12
- @app.route('/', methods=['GET'])
13
- def index():
14
- return app.send_static_file('index.html')
15
-
16
- # Serve assets from /ui/... and fallback to SPA (GET only)
17
- @app.route('/<path:path>', methods=['GET'])
18
- def spa_or_asset(path):
19
- file_path = os.path.join(app.static_folder, path)
20
- if os.path.isfile(file_path):
21
- return send_from_directory(app.static_folder, path)
22
- return send_from_directory(app.static_folder, 'index.html')
23
-
24
- # Quiet the favicon noise
25
- @app.route('/favicon.ico', methods=['GET'])
26
- def favicon():
27
- return ('', 204)
28
-
29
-
30
-
31
  id2label = {
32
  0: "Level 0: mild roast",
33
  1: "Level 1: emotional shade",
@@ -57,7 +35,6 @@ def ask_phi(prompt):
57
  print("Ollama error:", e)
58
  return "0"
59
 
60
-
61
  def _predict_impl():
62
  data = request.get_json(silent=True) or {}
63
  text = data.get("text", "").strip()
@@ -77,7 +54,10 @@ def _predict_impl():
77
  level = max(0, min(level, 7))
78
 
79
  roast_prompt = (
80
- "You are EmoNet’s snarky alter ego — a sasscore machine trained on sarcasm, late-night roasts, and internet chaos. But today, you’re in your flirty villain era. For any input text, reply with a short, teasingly devastating comeback that mixes charm with chaos. It should feel like emotional damage... but make it hot. Keep it clever, spicy, and seductive — no cruelty, no cringe. Think: if Gen Z flirted like a roast battle and a chaotic therapist whispered pickup lines mid-burn.\n\n"
 
 
 
81
  f"Sentence: \"{text}\"\nDamage Level: {level}\nRoast:"
82
  )
83
  roast = ask_phi(roast_prompt).strip()
@@ -89,16 +69,12 @@ def _predict_impl():
89
  "roast": roast
90
  })
91
 
92
- # Single handler serves both routes; explicit OPTIONS so preflight never gets hijacked
93
  @app.route("/predict", methods=["POST", "OPTIONS"])
94
- @app.route("/api/predict", methods=["POST", "OPTIONS"])
95
  def predict():
96
  if request.method == "OPTIONS":
97
  return ('', 204)
98
  return _predict_impl()
99
 
100
-
101
- # Debug helpers: see what routes are live
102
  @app.route("/__routes", methods=["GET"])
103
  def list_routes():
104
  return {"routes": [str(r) for r in app.url_map.iter_rules()]}
 
1
+ from flask import Flask, request, jsonify
2
  from flask_cors import CORS
 
3
  import requests
4
  import random
5
 
6
+ app = Flask(__name__)
 
7
  CORS(app, resources={r"/*": {"origins": "*"}})
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  id2label = {
10
  0: "Level 0: mild roast",
11
  1: "Level 1: emotional shade",
 
35
  print("Ollama error:", e)
36
  return "0"
37
 
 
38
  def _predict_impl():
39
  data = request.get_json(silent=True) or {}
40
  text = data.get("text", "").strip()
 
54
  level = max(0, min(level, 7))
55
 
56
  roast_prompt = (
57
+ "You are EmoNet’s snarky alter ego — a sasscore machine trained on sarcasm, "
58
+ "late-night roasts, and internet chaos. But today, you’re in your flirty villain era. "
59
+ "For any input text, reply with a short, teasingly devastating comeback that mixes "
60
+ "charm with chaos. Keep it clever, spicy, and seductive.\n\n"
61
  f"Sentence: \"{text}\"\nDamage Level: {level}\nRoast:"
62
  )
63
  roast = ask_phi(roast_prompt).strip()
 
69
  "roast": roast
70
  })
71
 
 
72
  @app.route("/predict", methods=["POST", "OPTIONS"])
 
73
  def predict():
74
  if request.method == "OPTIONS":
75
  return ('', 204)
76
  return _predict_impl()
77
 
 
 
78
  @app.route("/__routes", methods=["GET"])
79
  def list_routes():
80
  return {"routes": [str(r) for r in app.url_map.iter_rules()]}