-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
141 lines (95 loc) · 4.27 KB
/
app.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import os
from flask import Flask, request, send_file, redirect
from endpoints import random_math, random_word, wanted, welcomecard, sharpen, smooth, enhance, contour, find_edges, random_sentence
fallback_avatar = "https://bevels-files.vercel.app/discordblue.png"
app = Flask("Useless API")
@app.route("/", methods=["GET"])
def get_index():
return send_file("public/index.html")
@app.route("/styles.css", methods=["GET"])
def get_styles():
return send_file("public/styles.css")
@app.route("/welcomecard", methods=["GET"])
def generate_image():
text1 = request.args.get("text1")
text2 = request.args.get("text2")
background_url = request.args.get("background")
avatar_url = request.args.get("avatar")
if text1 == None or text2 == None or background_url == None:
return redirect(f"/welcomecard?background=https://cdn.modrinth.com/data/LMIZZNxZ/images/bd57c68a400e0722bc7132575ea7cec66ca529ab.png&text1=Welcome&text2=John Doe&avatar={fallback_avatar}")
if avatar_url == None:
avatar_url = fallback_avatar
print(f"Generating welcome card...")
return welcomecard.generate(text1, text2, background_url, avatar_url, fallback_avatar)
@app.route("/wanted", methods=["GET"])
def generate_wanted():
avatar_url = request.args.get("avatar")
if avatar_url == None:
avatar_url = fallback_avatar
print(f"Generating wanted card...")
return wanted.generate(avatar_url, fallback_avatar)
@app.route("/sharpen", methods=["GET"])
def generate_sharp():
image_url = request.args.get("image")
cycles = request.args.get("cycles")
if image_url == None:
return redirect(f"/sharpen?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
if cycles == None:
return redirect(f"/sharpen?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
print(f"Generating sharpened image ({cycles}x)")
return sharpen.generate(image_url, cycles)
@app.route("/smooth", methods=["GET"])
def generate_smooth():
image_url = request.args.get("image")
cycles = request.args.get("cycles")
if image_url == None:
return redirect(f"/smooth?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
if cycles == None:
return redirect(f"/smooth?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
print(f"Generating smoothed image ({cycles}x)")
return smooth.generate(image_url, cycles)
@app.route("/edge_enhance", methods=["GET"])
def generate_enhanced():
image_url = request.args.get("image")
cycles = request.args.get("cycles")
if image_url == None:
return redirect(f"/edge_enhance?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
if cycles == None:
return redirect(f"/edge_enhance?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
print(f"Generating enhanced image ({cycles}x)")
return enhance.generate(image_url, cycles)
@app.route("/contour", methods=["GET"])
def generate_contour():
image_url = request.args.get("image")
cycles = request.args.get("cycles")
if image_url == None:
return redirect(f"/contour?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
if cycles == None:
return redirect(f"/contour?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
print(f"Generating contoured image ({cycles}x)")
return contour.generate(image_url, cycles)
@app.route("/find_edges", methods=["GET"])
def generate_edge():
image_url = request.args.get("image")
cycles = request.args.get("cycles")
if image_url == None:
return redirect(f"/find_edges?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
if cycles == None:
return redirect(f"/find_edges?image=https://bevels-files.vercel.app/bsl.png&cycles=1")
print(f"Generating edged image ({cycles}x)")
return find_edges.generate(image_url, cycles)
@app.route("/random_math", methods=["GET"])
def generate_math():
return random_math.generate()
@app.route("/random_word", methods=["GET"])
def generate_word():
return random_word.generate()
@app.route("/random_sentence", methods=["GET"])
def generate_sentence():
length = request.args.get("length")
if length == None or length == 0:
return redirect(f"/random_sentence?length=5")
else:
return random_sentence.generate(length)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=False, port=int(os.environ.get("PORT", 8000)))