Spaces:
Running
Running
buletomato25
commited on
Commit
·
fbc9cec
1
Parent(s):
4e9c42f
google_login
Browse files- app.py +64 -29
- database.py +0 -3
- templates/index.html +5 -0
- templates/login.html +2 -1
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, request, jsonify, render_template, send_from_directory,redirect, make_response, Response, session
|
2 |
import base64
|
3 |
from pydub import AudioSegment # 変換用にpydubをインポート
|
4 |
import os
|
@@ -11,10 +11,12 @@ from pyannote.audio import Model, Inference
|
|
11 |
from pydub import AudioSegment
|
12 |
from flask_sqlalchemy import SQLAlchemy
|
13 |
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required
|
14 |
-
from database import db
|
15 |
from users import Users
|
16 |
from werkzeug.security import generate_password_hash, check_password_hash
|
17 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
18 |
|
19 |
|
20 |
# Hugging Face のトークン取得(環境変数 HF に設定)
|
@@ -34,6 +36,20 @@ inference = Inference(model)
|
|
34 |
app = Flask(__name__)
|
35 |
|
36 |
app.config['SECRET_KEY'] = os.urandom(24)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# データベース設定
|
38 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
|
39 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
@@ -45,7 +61,7 @@ db.init_app(app)
|
|
45 |
login_manager = LoginManager()
|
46 |
login_manager.init_app(app)
|
47 |
login_manager.login_view = "login"
|
48 |
-
|
49 |
@login_manager.user_loader
|
50 |
def load_user(user_id):
|
51 |
return Users.query.get(int(user_id))
|
@@ -120,46 +136,65 @@ def top():
|
|
120 |
return redirect('/login')
|
121 |
|
122 |
# ログイン後画面
|
123 |
-
@app.route('/
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# フィードバック画面(テンプレート: feedback.html)
|
135 |
@app.route('/feedback', methods=['GET', 'POST'])
|
136 |
def feedback():
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
138 |
return render_template('feedback.html', users=users)
|
139 |
|
140 |
# 会話詳細画面(テンプレート: talkDetail.html)
|
141 |
@app.route('/talk_detail', methods=['GET', 'POST'])
|
142 |
def talk_detail():
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
144 |
return render_template('talkDetail.html', users=users)
|
145 |
|
146 |
# ログイン画面(テンプレート: login.html)
|
147 |
-
@app.route('/login'
|
148 |
def login():
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
|
164 |
# 登録画面(テンプレート: new_person.html)
|
165 |
@app.route('/new_person', methods=['GET', 'POST'])
|
|
|
1 |
+
from flask import Flask, request, jsonify, render_template, send_from_directory,redirect, make_response, Response, session, url_for
|
2 |
import base64
|
3 |
from pydub import AudioSegment # 変換用にpydubをインポート
|
4 |
import os
|
|
|
11 |
from pydub import AudioSegment
|
12 |
from flask_sqlalchemy import SQLAlchemy
|
13 |
from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required
|
|
|
14 |
from users import Users
|
15 |
from werkzeug.security import generate_password_hash, check_password_hash
|
16 |
from dotenv import load_dotenv
|
17 |
+
from google.oauth2 import id_token
|
18 |
+
from google_auth_oauthlib.flow import Flow
|
19 |
+
from google.auth.transport import requests as google_requests
|
20 |
|
21 |
|
22 |
# Hugging Face のトークン取得(環境変数 HF に設定)
|
|
|
36 |
app = Flask(__name__)
|
37 |
|
38 |
app.config['SECRET_KEY'] = os.urandom(24)
|
39 |
+
|
40 |
+
# Google OAuth 2.0の設定
|
41 |
+
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
|
42 |
+
GOOGLE_CLIENT_ID = "228160683186-6u7986qsfhcv3kd9iqtv08iphpl4gdk2.apps.googleusercontent.com"
|
43 |
+
GOOGLE_CLIENT_SECRET = "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"
|
44 |
+
REDIRECT_URI = "http://127.0.0.1:7860/callback"
|
45 |
+
|
46 |
+
flow = Flow.from_client_secrets_file(
|
47 |
+
'client_secret.json',
|
48 |
+
scopes=["openid", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"],
|
49 |
+
redirect_uri=REDIRECT_URI
|
50 |
+
)
|
51 |
+
|
52 |
+
"""
|
53 |
# データベース設定
|
54 |
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
|
55 |
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
|
|
61 |
login_manager = LoginManager()
|
62 |
login_manager.init_app(app)
|
63 |
login_manager.login_view = "login"
|
64 |
+
"""
|
65 |
@login_manager.user_loader
|
66 |
def load_user(user_id):
|
67 |
return Users.query.get(int(user_id))
|
|
|
136 |
return redirect('/login')
|
137 |
|
138 |
# ログイン後画面
|
139 |
+
@app.route('/callback')
|
140 |
+
def callback():
|
141 |
+
flow.fetch_token(authorization_response=request.url)
|
142 |
+
|
143 |
+
if not session['state'] == request.args['state']:
|
144 |
+
return 'State mismatch error', 400
|
145 |
+
|
146 |
+
credentials = flow.credentials
|
147 |
+
request_session = google_requests.Request()
|
148 |
|
149 |
+
id_info = id_token.verify_oauth2_token(
|
150 |
+
credentials.id_token, request_session, GOOGLE_CLIENT_ID
|
151 |
+
)
|
152 |
+
|
153 |
+
session['google_id'] = id_info.get("sub")
|
154 |
+
session['email'] = id_info.get("email")
|
155 |
+
session['name'] = id_info.get("name")
|
156 |
+
|
157 |
+
return redirect(url_for('index'))
|
158 |
|
159 |
# フィードバック画面(テンプレート: feedback.html)
|
160 |
@app.route('/feedback', methods=['GET', 'POST'])
|
161 |
def feedback():
|
162 |
+
if 'google_id' not in session:
|
163 |
+
return redirect(url_for('login'))
|
164 |
+
user_info = {
|
165 |
+
'name': session.get('name'),
|
166 |
+
'email': session.get('email')
|
167 |
+
}
|
168 |
return render_template('feedback.html', users=users)
|
169 |
|
170 |
# 会話詳細画面(テンプレート: talkDetail.html)
|
171 |
@app.route('/talk_detail', methods=['GET', 'POST'])
|
172 |
def talk_detail():
|
173 |
+
if 'google_id' not in session:
|
174 |
+
return redirect(url_for('login'))
|
175 |
+
user_info = {
|
176 |
+
'name': session.get('name'),
|
177 |
+
'email': session.get('email')
|
178 |
+
}
|
179 |
return render_template('talkDetail.html', users=users)
|
180 |
|
181 |
# ログイン画面(テンプレート: login.html)
|
182 |
+
@app.route('/login')
|
183 |
def login():
|
184 |
+
authorization_url, state = flow.authorization_url()
|
185 |
+
session['state'] = state
|
186 |
+
return redirect(authorization_url)
|
187 |
+
|
188 |
+
# インデックス画面(テンプレート: index.html)
|
189 |
+
@app.route('/index')
|
190 |
+
def index():
|
191 |
+
if 'google_id' not in session:
|
192 |
+
return redirect(url_for('login'))
|
193 |
+
user_info = {
|
194 |
+
'name': session.get('name'),
|
195 |
+
'email': session.get('email')
|
196 |
+
}
|
197 |
+
return render_template('index.html', user=user_info)
|
198 |
|
199 |
# 登録画面(テンプレート: new_person.html)
|
200 |
@app.route('/new_person', methods=['GET', 'POST'])
|
database.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
from flask_sqlalchemy import SQLAlchemy
|
2 |
-
|
3 |
-
db = SQLAlchemy()
|
|
|
|
|
|
|
|
templates/index.html
CHANGED
@@ -4,6 +4,10 @@
|
|
4 |
<meta charset="UTF-8" />
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
<title>Voice Recorder Interface</title>
|
|
|
|
|
|
|
|
|
7 |
<style>
|
8 |
body {
|
9 |
display: flex;
|
@@ -121,6 +125,7 @@
|
|
121 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
122 |
</head>
|
123 |
<body>
|
|
|
124 |
<!-- トグルスイッチ:基準音声保存モード -->
|
125 |
<div class="toggle-container">
|
126 |
<span class="toggle-label">基準音声を保存</span>
|
|
|
4 |
<meta charset="UTF-8" />
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
<title>Voice Recorder Interface</title>
|
7 |
+
<link
|
8 |
+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
|
9 |
+
rel="stylesheet"
|
10 |
+
/>
|
11 |
<style>
|
12 |
body {
|
13 |
display: flex;
|
|
|
125 |
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
126 |
</head>
|
127 |
<body>
|
128 |
+
<h1>ようこそ, {{ user.name }} さん!</h1>
|
129 |
<!-- トグルスイッチ:基準音声保存モード -->
|
130 |
<div class="toggle-container">
|
131 |
<span class="toggle-label">基準音声を保存</span>
|
templates/login.html
CHANGED
@@ -140,7 +140,7 @@ history-button:hover {
|
|
140 |
<body>
|
141 |
<form method="POST">
|
142 |
<div class="container">
|
143 |
-
<h2
|
144 |
<div>
|
145 |
<label for="">ユーザ名</label>
|
146 |
<input type="text" name="username" />
|
@@ -151,6 +151,7 @@ history-button:hover {
|
|
151 |
<br />
|
152 |
</div>
|
153 |
<div class="flex">
|
|
|
154 |
<input
|
155 |
type="submit"
|
156 |
class="history-button"
|
|
|
140 |
<body>
|
141 |
<form method="POST">
|
142 |
<div class="container">
|
143 |
+
<h2>Googleあかうんとでログイン</h2>
|
144 |
<div>
|
145 |
<label for="">ユーザ名</label>
|
146 |
<input type="text" name="username" />
|
|
|
151 |
<br />
|
152 |
</div>
|
153 |
<div class="flex">
|
154 |
+
<button id="login-btn" class="history-button">Googleでログイン</button>
|
155 |
<input
|
156 |
type="submit"
|
157 |
class="history-button"
|