-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
89 lines (72 loc) · 2.43 KB
/
app.py
File metadata and controls
89 lines (72 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from flask import Flask, request, jsonify
from flask_cors import CORS
from dotenv import load_dotenv
import os
import pandas as pd
import numpy as np
from openai import OpenAI
# Load environment variables
load_dotenv()
# Initialize Flask app
app = Flask(__name__)
CORS(app)
# Initialize OpenAI client
openai_client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
# AR Debt Demon Feature
@app.route('/api/debt-demon', methods=['POST'])
def generate_debt_demon():
data = request.get_json()
debt_amount = data.get('debt_amount', 0)
debt_increasing = data.get('debt_increasing', True)
demon_size = debt_amount / 1000 # Scale demon to debt
demon_texture = "angry" if debt_increasing else "sad"
return jsonify({
"size": demon_size,
"mood": demon_texture
})
# Time Prison Calculator
@app.route('/api/time-prison', methods=['POST'])
def calculate_time_cost():
data = request.get_json()
item_price = data.get('item_price', 0)
hourly_wage = data.get('hourly_wage', 0)
commute_minutes = data.get('commute_minutes', 0)
work_hours = item_price / hourly_wage if hourly_wage > 0 else 0
total_hours = work_hours + (commute_minutes / 60)
return jsonify({
"work_hours": work_hours,
"total_hours": total_hours
})
# Financial Tarot
@app.route('/api/tarot-reading', methods=['POST'])
def generate_tarot_reading():
data = request.get_json()
transaction = data.get('transaction', {})
# Generate tarot reading using GPT-4
prompt = f"""Analyze this purchase: {transaction}.
Give a mystical warning/approval using:
- Past spending
- Local price comparisons
- User's savings goals"""
try:
response = openai_client.completions.create(
model="gpt-4",
prompt=prompt,
max_tokens=150
)
reading = response.choices[0].text.strip()
except Exception as e:
reading = "The financial spirits are silent at the moment."
return jsonify({"reading": reading})
# Pain-Point PayPal
@app.route('/api/pain-feedback', methods=['POST'])
def trigger_pain():
data = request.get_json()
overspend_amount = data.get('overspend_amount', 0)
pain_duration = overspend_amount / 10 # $10 = 1 second
return jsonify({
"pain_duration": pain_duration,
"feedback_type": "vibration"
})
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)