-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
116 lines (93 loc) · 3.04 KB
/
main.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
"""
Emotion API (https://emotionapi.darkmash.repl.co)
By ~ Darkmash
"""
from deepface import DeepFace
from flask import Flask
import datetime
import requests
import random
import logging
import base64
import cv2
import os
app = Flask(__name__)
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
@app.route('/')
def main_func_():
print("PING__UPTIME")
return """
<meta
property="og:image"
content="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
<meta
name="description"
content="An API for detecting emotion.."
/>
<meta name="keywords" content="api , emotion ,darkmash , tools , startup , coders" />
<link
rel="icon"
type="image/png"
href="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
<title>Emotion API ~ Darkmash</title>
######## DARKMASH ~ EMOTION API ~ V.1.0.0 #########<br>
To use the service ,<br>
/service/img_url_encoded_with_base64<br>
####################################################
"""
@app.route('/service/<file_url>')
def main_func(file_url):
try:
base64_bytes = file_url.encode("ascii")
sample_string_bytes = base64.b64decode(base64_bytes)
file_url = sample_string_bytes.decode("ascii")
response = requests.get(file_url)
if response.status_code:
in_t = f"{random.randint(90000000,90000000000000)}.{file_url.split('.')[-1]}"
fp = open(in_t, 'wb')
fp.write(response.content)
fp.close()
else:
return """
<meta
property="og:image"
content="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
<title>Emotion API ~ Darkmash</title>
<meta
name="description"
content="An API for detecting emotion.. || ERRRORRR!!"
/>
<meta name="keywords" content="api , emotion ,darkmash , tools , startup , coders" />
<link
rel="icon"
type="image/png"
href="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
Some error regarding the link happend.. (somethin like the site was down)"""
img = cv2.imread(in_t)
os.remove(in_t)
result = DeepFace.analyze(img, actions=['emotion'])
return result
except:
return """
<meta
property="og:image"
content="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
<title>Emotion API ~ Darkmash</title>
<meta
name="description"
content="An API for detecting emotion.. || ERRRORRR!!"
/>
<meta name="keywords" content="api , emotion ,darkmash , tools , startup , coders" />
<link
rel="icon"
type="image/png"
href="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
Some error occured.. (maybe something related to the link)"""
app.run(host="0.0.0.0", port=8080)