File size: 3,180 Bytes
fbfa98a
 
 
 
db6e2f8
fbfa98a
6e5ed1f
 
 
 
db6e2f8
fbfa98a
 
db6e2f8
fbfa98a
 
 
db6e2f8
6e5ed1f
 
 
fbfa98a
1e7a0a5
db6e2f8
fbfa98a
 
 
db6e2f8
6e5ed1f
 
 
 
db6e2f8
35eab52
 
 
db6e2f8
35eab52
 
 
 
 
 
db6e2f8
35eab52
db6e2f8
 
35eab52
 
 
db6e2f8
35eab52
db6e2f8
35eab52
db6e2f8
 
35eab52
 
 
 
db6e2f8
35eab52
 
db6e2f8
35eab52
db6e2f8
35eab52
db6e2f8
 
fbfa98a
 
35eab52
 
 
3ab3d9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35eab52
fbfa98a
 
35eab52
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
import os
import requests
import json
from io import BytesIO

from flask import Flask, jsonify, render_template, request, send_file
from flask import Flask, redirect, url_for, session, request, jsonify, render_template
from google.oauth2 import id_token
from google.auth.transport import requests as grequests
import os

from modules.inference import infer_t5
from modules.dataset import query_emotion

# https://huggingface.co/settings/tokens
# https://huggingface.co/spaces/{username}/{space}/settings
API_TOKEN = os.getenv("BIG_GAN_TOKEN")

CLIENT_ID = "your_google_client_id"
CLIENT_SECRET = os.environ.get("GOOGLE_CLIENT_SECRET")

app = Flask(__name__)
app.secret_key = os.urandom(24)

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/login")
def login():
    return redirect("https://accounts.google.com/o/oauth2/auth?response_type=code&client_id={}&redirect_uri=http://localhost:3000/callback&scope=email%20profile&access_type=offline".format(CLIENT_ID))


# @app.route("/infer_biggan")
# def biggan():
#     input = request.args.get("input")

#     output = requests.request(
#         "POST",
#         "https://api-inference.huggingface.co/models/osanseviero/BigGAN-deep-128",
#         headers={"Authorization": f"Bearer {API_TOKEN}"},
#         data=json.dumps(input),
#     )

#     return send_file(BytesIO(output.content), mimetype="image/png")


# @app.route("/infer_t5")
# def t5():
#     input = request.args.get("input")

#     output = infer_t5(input)

#     return jsonify({"output": output})


# @app.route("/query_emotion")
# def emotion():
#     start = request.args.get("start")
#     end = request.args.get("end")

#     print(start)
#     print(end)

#     output = query_emotion(int(start), int(end))

#     return jsonify({"output": output})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)




# @app.route("/callback")
# def callback():
#     code = request.args.get("code")
#     token_response = grequests.post("https://oauth2.googleapis.com/token", 
#                                     data={
#                                         "code": code,
#                                         "client_id": CLIENT_ID,
#                                         "client_secret": CLIENT_SECRET,
#                                         "redirect_uri": "http://localhost:3000/callback",
#                                         "grant_type": "authorization_code"
#                                     })
#     token_data = token_response.json()
#     access_token = token_data.get("access_token")
#     id_info = id_token.verify_oauth2_token(token_data.get("id_token"), grequests.Request(), CLIENT_ID)

#     # Store user information in session
#     session['user'] = id_info

#     return redirect(url_for("profile"))

# @app.route("/profile")
# def profile():
#     user = session.get('user')
#     if user:
#         return render_template("profile.html", user=user)
#     else:
#         return "User not authenticated"

# @app.route("/logout")
# def logout():
#     session.pop('user', None)
#     return redirect(url_for("index"))

# if __name__ == "__main__":
#     app.run(debug=True)