buletomato25 commited on
Commit
1da3080
·
1 Parent(s): 118fe70

delete_login

Browse files
app.py CHANGED
@@ -14,8 +14,7 @@ from dotenv import load_dotenv
14
  from google.oauth2 import id_token
15
  from google_auth_oauthlib.flow import Flow
16
  from google.auth.transport import requests as google_requests
17
- from new_record import record_bp
18
- from login import login_bp
19
 
20
 
21
  # Hugging Face のトークン取得(環境変数 HF に設定)
@@ -94,14 +93,12 @@ def generate_filename(random_length):
94
  filename = f"{current_time}_{random_string}.wav"
95
  return filename
96
 
97
- app.register_blueprint(record_bp)
98
- app.register_blueprint(login_bp)
99
-
100
  # トップページ(テンプレート: index.html)
101
  @app.route('/')
102
  def top():
103
  return redirect('index')
104
 
 
105
  # フィードバック画面(テンプレート: feedback.html)
106
  @app.route('/feedback', methods=['GET', 'POST'])
107
  def feedback():
@@ -142,17 +139,6 @@ def index():
142
  """
143
  return render_template('index.html')
144
 
145
- # 登録画面(テンプレート: new_person.html)
146
- @app.route('/new_person', methods=['GET', 'POST'])
147
- def new_person():
148
- if 'google_id' not in session:
149
- return redirect(url_for('login'))
150
- user_info = {
151
- 'name': session.get('name'),
152
- 'email': session.get('email')
153
- }
154
- return render_template('new_person.html', user=user_info)
155
-
156
  @app.before_request
157
  def before_request():
158
  # リクエストのたびにセッションの寿命を更新する
 
14
  from google.oauth2 import id_token
15
  from google_auth_oauthlib.flow import Flow
16
  from google.auth.transport import requests as google_requests
17
+
 
18
 
19
 
20
  # Hugging Face のトークン取得(環境変数 HF に設定)
 
93
  filename = f"{current_time}_{random_string}.wav"
94
  return filename
95
 
 
 
 
96
  # トップページ(テンプレート: index.html)
97
  @app.route('/')
98
  def top():
99
  return redirect('index')
100
 
101
+
102
  # フィードバック画面(テンプレート: feedback.html)
103
  @app.route('/feedback', methods=['GET', 'POST'])
104
  def feedback():
 
139
  """
140
  return render_template('index.html')
141
 
 
 
 
 
 
 
 
 
 
 
 
142
  @app.before_request
143
  def before_request():
144
  # リクエストのたびにセッションの寿命を更新する
client_secret.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "web": {
3
- "client_id": "228160683186-6u7986qsfhcv3kd9iqtv08iphpl4gdk2.apps.googleusercontent.com",
4
- "project_id": "justtalk-454100",
5
- "auth_uri": "https://accounts.google.com/o/oauth2/auth",
6
- "token_uri": "https://oauth2.googleapis.com/token",
7
- "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
8
- "client_secret": "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",
9
- "redirect_uris": "http://127.0.0.1:7860/callback"
10
- }
11
- }
 
 
 
 
 
 
 
 
 
 
 
 
login.py DELETED
@@ -1,51 +0,0 @@
1
- from flask import Blueprint, request, redirect, session, url_for, render_template
2
- import os
3
- from google.oauth2 import id_token
4
- from google_auth_oauthlib.flow import Flow
5
- from google.auth.transport import requests as google_requests
6
-
7
- login_bp = Blueprint('login', __name__)
8
-
9
- # Google OAuth 2.0 の設定
10
- os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
11
- GOOGLE_CLIENT_ID = "228160683186-6u7986qsfhcv3kd9iqtv08iphpl4gdk2.apps.googleusercontent.com"
12
- GOOGLE_CLIENT_SECRET = "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"
13
- REDIRECT_URI = "http://127.0.0.1:7860/callback"
14
-
15
- flow = Flow.from_client_secrets_file(
16
- 'client_secret.json',
17
- scopes=["openid", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"],
18
- redirect_uri=REDIRECT_URI
19
- )
20
-
21
- @login_bp.route('/login')
22
- def login():
23
- authorization_url, state = flow.authorization_url()
24
- session['state'] = state
25
- return redirect(authorization_url)
26
-
27
- @login_bp.route('/callback')
28
- def callback():
29
- flow.fetch_token(authorization_response=request.url)
30
-
31
- session_state = session.get('state')
32
- request_state = request.args.get('state')
33
-
34
- if session_state is None or session_state != request_state:
35
- print(f"State mismatch error: session_state={session_state}, request_state={request_state}")
36
- return 'State mismatch error', 400
37
-
38
- credentials = flow.credentials
39
- request_session = google_requests.Request()
40
-
41
- id_info = id_token.verify_oauth2_token(
42
- credentials.id_token, request_session, GOOGLE_CLIENT_ID
43
- )
44
-
45
- session['google_id'] = id_info.get("sub")
46
- session['email'] = id_info.get("email")
47
- session['name'] = id_info.get("name")
48
-
49
- return redirect(url_for('new_person'))
50
-
51
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
new_record.py DELETED
@@ -1,43 +0,0 @@
1
- from flask import Blueprint, request, jsonify
2
- import os
3
- import base64
4
- from pydub import AudioSegment
5
-
6
- record_bp = Blueprint('record', __name__)
7
-
8
- # 録音データの保存先ディレクトリ
9
- record_data_dir = "record_data"
10
- os.makedirs(record_data_dir, exist_ok=True)
11
-
12
- @record_bp.route('/upload_audio', methods=['POST'])
13
- def upload_audio():
14
- try:
15
- data = request.get_json()
16
- if not data or 'audio_data' not in data or 'user_name' not in data:
17
- return jsonify({"error": "音声データまたはユーザー名がありません"}), 400
18
-
19
- user_name = data['user_name'].replace(" ", "_") # 空白をアンダースコアに変換
20
- audio_binary = base64.b64decode(data['audio_data'])
21
-
22
- # 保存先のファイルパス
23
- audio_path = os.path.join(record_data_dir, f"{user_name}.wav")
24
-
25
- # 一時ファイルとして保存
26
- temp_audio_path = os.path.join(record_data_dir, "temp_audio")
27
- with open(temp_audio_path, 'wb') as f:
28
- f.write(audio_binary)
29
-
30
- # pydub を使って WAV に変換
31
- try:
32
- audio = AudioSegment.from_file(temp_audio_path, format="webm")
33
- except Exception:
34
- audio = AudioSegment.from_file(temp_audio_path)
35
-
36
- audio.export(audio_path, format="wav")
37
- os.remove(temp_audio_path)
38
-
39
- return jsonify({"success": True, "message": f"音声が {audio_path} に保存されました"}), 200
40
-
41
- except Exception as e:
42
- print("Error in /upload_audio:", str(e))
43
- return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/index.html CHANGED
@@ -128,15 +128,6 @@
128
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
129
  </head>
130
  <body>
131
- <header>
132
- <div></div>
133
- <div>
134
- <button class="result-button" id="historyButton" onclick="showLogin()">
135
- ログイン
136
- </button>
137
- </div>
138
- </header>
139
-
140
  <!-- トグルスイッチ:基準音声保存モード -->
141
  <div class="toggle-container">
142
  <span class="toggle-label">基準音声を保存</span>
 
128
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
129
  </head>
130
  <body>
 
 
 
 
 
 
 
 
 
131
  <!-- トグルスイッチ:基準音声保存モード -->
132
  <div class="toggle-container">
133
  <span class="toggle-label">基準音声を保存</span>
templates/login.html DELETED
@@ -1,209 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="ja">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>ログイン画面</title>
7
- <style>
8
- @charset "UTF-8";
9
- body {
10
- font-family: Arial, sans-serif;
11
- padding: 20px;
12
- background-color: #f4f4f4;
13
- height: 100vh;
14
- display: flex;
15
- justify-content: center;
16
- align-items: center;
17
- }
18
-
19
- h2 {
20
- margin-bottom: 20px;
21
- text-align: center;
22
- }
23
-
24
- a {
25
- text-decoration: none;
26
- color: #000000cc;
27
- }
28
- a:hover {
29
- text-decoration: underline;
30
- }
31
- .container {
32
- max-width: 800px;
33
-
34
- background-color: #fff;
35
- padding: 20px 80px;
36
- border-radius: 8px;
37
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
38
- }
39
-
40
- #transcription {
41
- white-space: pre-wrap;
42
- padding: 10px;
43
- background-color: #e9e9e9;
44
- border-radius: 4px;
45
- margin-bottom: 20px;
46
- max-height: 400px;
47
- overflow-y: auto;
48
- }
49
- button {
50
- margin: 5px;
51
- padding: 10px 10px;
52
- border: none;
53
- border-radius: 4px;
54
- background-color: #007bff;
55
- color: #fff;
56
- cursor: pointer;
57
- }
58
- .history-button {
59
- margin-top: 20px;
60
-
61
- padding: 10px 20px;
62
- background-color: #007bff;
63
- color: white;
64
- border: none;
65
- border-radius: 5px;
66
- cursor: pointer;
67
- }
68
- history-button:hover {
69
- background-color: #0056b3;
70
- }
71
-
72
- .flex {
73
- display: flex;
74
- justify-content: center;
75
- }
76
- .new-person {
77
- text-align: center;
78
- }
79
-
80
- .controls {
81
- display: flex;
82
- flex-direction: column;
83
- align-items: center;
84
- }
85
- .record-button {
86
- width: 80px;
87
- height: 80px;
88
- background-color: transparent;
89
- border-radius: 50%;
90
-
91
- display: flex;
92
- justify-content: center;
93
- align-items: center;
94
- cursor: pointer;
95
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
96
- transition: all 0.2s ease;
97
- }
98
-
99
- .record-icon {
100
- width: 60px;
101
- height: 60px;
102
- background-color: #d32f2f;
103
- border-radius: 50%;
104
- transition: all 0.2s ease;
105
- }
106
-
107
- .recording .record-icon {
108
- width: 40px;
109
- height: 40px;
110
- border-radius: 10%;
111
- }
112
-
113
- .record-p {
114
- border: 2px dashed #0000008c;
115
- }
116
-
117
- .disabled {
118
- background-color: gray;
119
- cursor: not-allowed;
120
- }
121
-
122
- .record-icon.recording {
123
- width: 40px;
124
- height: 40px;
125
- border-radius: 0;
126
- }
127
-
128
- .new-person-right-container {
129
- padding-left: 20px;
130
- }
131
-
132
- .record-container {
133
- display: flex;
134
- justify-content: center;
135
- }
136
-
137
- </style>
138
-
139
- </head>
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" />
147
- <br />
148
- <br />
149
- <label for="">パスワード</label>
150
- <input type="password" name="password" />
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"
158
- id="loginButton"
159
- onclick="showRecorder()"
160
- value="ログイン"
161
- />
162
- </div>
163
- </form>
164
- <div class="new-person">
165
- <p><a href="new_person.php" class="new-person">新規会員登録をする</a></p>
166
- </div>
167
- </div>
168
-
169
-
170
-
171
- <script>
172
- // 会話データを表示
173
- async function displayTranscription() {
174
- const transcriptionElement = document.getElementById("transcription");
175
-
176
- try {
177
- // バックエンドからデータを取得(デモ用のURLを指定)
178
- const response = await fetch("/api/transcription");
179
- if (!response.ok) throw new Error("データ取得に失敗しました。");
180
-
181
- const data = await response.json();
182
-
183
- // 会話内容を整形して表示
184
- const formattedText = data.conversations
185
- .map((conv, index) => `【${conv.speaker}】 ${conv.text}`)
186
- .join("\n");
187
-
188
- transcriptionElement.textContent = formattedText;
189
- } catch (error) {
190
- transcriptionElement.textContent = `エラー: ${error.message}`;
191
- console.error("データ取得エラー:", error);
192
- }
193
- }
194
-
195
- // 初期化処理
196
- displayTranscription();
197
-
198
- //画面遷移
199
- function showRecorder() {
200
- // 録音画面へ遷移
201
- window.location.href = "/index";
202
- }
203
- function showFeedback() {
204
- // フィードバック画面へ遷移
205
- window.location.href = "/feedback";
206
- }
207
- </script>
208
- </body>
209
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/new_person.html DELETED
@@ -1,303 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="ja">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <style>
7
- @charset "UTF-8";
8
- body {
9
- font-family: Arial, sans-serif;
10
- padding: 20px;
11
- background-color: #f4f4f4;
12
- height: 100vh;
13
- display: flex;
14
- justify-content: center;
15
- align-items: center;
16
- }
17
-
18
- h2 {
19
- margin-bottom: 20px;
20
- text-align: center;
21
- }
22
-
23
- a {
24
- text-decoration: none;
25
- color: #000000cc;
26
- }
27
- a:hover {
28
- text-decoration: underline;
29
- }
30
- .container {
31
- max-width: 800px;
32
-
33
- background-color: #fff;
34
- padding: 20px 80px;
35
- border-radius: 8px;
36
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
37
- }
38
-
39
- #transcription {
40
- white-space: pre-wrap;
41
- padding: 10px;
42
- background-color: #e9e9e9;
43
- border-radius: 4px;
44
- margin-bottom: 20px;
45
- max-height: 400px;
46
- overflow-y: auto;
47
- }
48
- button {
49
- margin: 5px;
50
- padding: 10px 10px;
51
- border: none;
52
- border-radius: 4px;
53
- background-color: #007bff;
54
- color: #fff;
55
- cursor: pointer;
56
- }
57
- .history-button {
58
- margin-top: 20px;
59
-
60
- padding: 10px 20px;
61
- background-color: #007bff;
62
- color: white;
63
- border: none;
64
- border-radius: 5px;
65
- cursor: pointer;
66
- }
67
- history-button:hover {
68
- background-color: #0056b3;
69
- }
70
-
71
- .flex {
72
- display: flex;
73
- justify-content: center;
74
- }
75
- .new-person {
76
- text-align: center;
77
- }
78
-
79
- .controls {
80
- display: flex;
81
- flex-direction: column;
82
- align-items: center;
83
- }
84
- .record-button {
85
- width: 80px;
86
- height: 80px;
87
- background-color: transparent;
88
- border-radius: 50%;
89
-
90
- display: flex;
91
- justify-content: center;
92
- align-items: center;
93
- cursor: pointer;
94
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
95
- transition: all 0.2s ease;
96
- }
97
-
98
- .record-icon {
99
- width: 60px;
100
- height: 60px;
101
- background-color: #d32f2f;
102
- border-radius: 50%;
103
- transition: all 0.2s ease;
104
- }
105
-
106
- .recording .record-icon {
107
- width: 40px;
108
- height: 40px;
109
- border-radius: 10%;
110
- }
111
-
112
- .record-p {
113
- border: 2px dashed #0000008c;
114
- }
115
-
116
- .disabled {
117
- background-color: gray;
118
- cursor: not-allowed;
119
- }
120
-
121
- .record-icon.recording {
122
- width: 40px;
123
- height: 40px;
124
- border-radius: 0;
125
- }
126
-
127
- .new-person-right-container {
128
- padding-left: 20px;
129
- }
130
-
131
- .record-container {
132
- display: flex;
133
- justify-content: center;
134
- }
135
-
136
- .tc {
137
- text-align: center;
138
- }
139
- </style>
140
- <title>ユーザー登録画面</title>
141
- <link
142
- href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
143
- rel="stylesheet"
144
- />
145
- </head>
146
- <body>
147
- <h1>ようこそ, {{ user.name }} さん!</h1>
148
- <form method="POST">
149
- <div class="container">
150
- <h2>音声登録</h2>
151
- <div class="flex">
152
- <div class="new-person-right-container">
153
- <label for="">
154
- 録音ボタンを押した後、10秒間声を録音してください</label
155
- >
156
- <br />
157
- <p class="record-p">
158
- 例文:昔々、あるところにおばあさんとおじいさんがいました。<br />
159
- おばあさんは川に洗濯に、おじいさんは山に芝刈りに行きました。
160
- </p>
161
- <div class="record-container">
162
- <button
163
- class="record-button"
164
- id="recordButton"
165
- onclick="toggleRecording()"
166
- >
167
- <div class="record-icon" id="recordIcon"></div>
168
- </button>
169
- </div>
170
-
171
- <p id="countdownDisplay" class="tc"></p>
172
- </div>
173
- </div>
174
-
175
- <div class="flex">
176
- <button
177
- class="history-button disabled"
178
- id="detailButton submit"
179
- onclick="showRecorder()"
180
- >
181
- 音声登録完了
182
- </button>
183
- </div>
184
- </div>
185
- </form>
186
- <script>
187
- let mediaRecorder;
188
- let audioChunks = [];
189
- let countdownTimer;
190
- let isAudioRecorded = false;
191
- sessionStorage.setItem("userName", "{{ user.name }}");
192
- async function toggleRecording() {
193
- const recordButton = document.getElementById("recordButton");
194
- const countdownDisplay = document.getElementById("countdownDisplay");
195
-
196
- recordButton.disabled = true; // ボタンを無効化(連打防止)
197
- countdownDisplay.textContent = "録音中…"; // 初期表示
198
- isAudioRecorded = false;
199
-
200
- try {
201
- const stream = await navigator.mediaDevices.getUserMedia({
202
- audio: true,
203
- });
204
- mediaRecorder = new MediaRecorder(stream);
205
- audioChunks = [];
206
-
207
- mediaRecorder.ondataavailable = (event) => {
208
- if (event.data.size > 0) {
209
- audioChunks.push(event.data);
210
- }
211
- };
212
-
213
- mediaRecorder.onstop = () => {
214
- sendAudioChunks([...audioChunks]); // 録音データをサーバーに送信
215
- audioChunks = [];
216
- recordButton.disabled = false;
217
- countdownDisplay.textContent = "";
218
- isAudioRecorded = true;
219
- validateForm();
220
- };
221
-
222
- mediaRecorder.start();
223
- startCountdown(10, countdownDisplay);
224
-
225
- setTimeout(() => {
226
- if (mediaRecorder.state === "recording") {
227
- mediaRecorder.stop();
228
- }
229
- }, 10000);
230
- } catch (error) {
231
- console.error("マイクのアクセスに失敗しました:", error);
232
- recordButton.disabled = false;
233
- countdownDisplay.textContent = "";
234
- }
235
- }
236
-
237
- function startCountdown(seconds, displayElement) {
238
- let remaining = seconds;
239
- displayElement.textContent = `録音終了まで: ${remaining}秒`;
240
-
241
- countdownTimer = setInterval(() => {
242
- remaining--;
243
- displayElement.textContent = `録音終了まで: ${remaining}秒`;
244
-
245
- if (remaining <= 0) {
246
- clearInterval(countdownTimer);
247
- }
248
- }, 1000);
249
- }
250
-
251
- function sendAudioChunks(chunks) {
252
- const userName = sessionStorage.getItem("userName"); // ユーザー名を取得
253
- if (!userName) {
254
- alert("ユーザー名が取得できません。ログインしてください。");
255
- return;
256
- }
257
-
258
- const audioBlob = new Blob(chunks, { type: "audio/wav" });
259
- const reader = new FileReader();
260
- reader.onloadend = () => {
261
- const base64String = reader.result.split(",")[1]; // Base64 に変換
262
- fetch("/upload_audio", {
263
- method: "POST",
264
- headers: { "Content-Type": "application/json" },
265
- body: JSON.stringify({
266
- audio_data: base64String,
267
- user_name: userName,
268
- }),
269
- })
270
- .then((response) => response.json())
271
- .then((data) => {
272
- if (data.success) {
273
- alert("音声がサーバーに送信されました。");
274
- isAudioRecorded = true;
275
- validateForm();
276
- } else {
277
- alert("音声の送信に失敗しました。");
278
- }
279
- })
280
- .catch((error) => {
281
- console.error("送信エラー:", error);
282
- alert("音声の送信中にエラーが発生しました。");
283
- });
284
- };
285
- reader.readAsDataURL(audioBlob);
286
- }
287
-
288
- // ユーザー名をセッションに保存(ログイン後に実行)
289
- function setUserName(userName) {
290
- sessionStorage.setItem("userName", userName);
291
- }
292
-
293
- // 初期化処理
294
- displayTranscription();
295
-
296
- //画面遷移
297
- function showRecorder() {
298
- // 録音画面へ遷移
299
- window.location.href = "/index";
300
- }
301
- </script>
302
- </body>
303
- </html>