Spaces:
Running
Running
buletomato25
commited on
Commit
·
4fe2183
1
Parent(s):
74cdf57
fix_login
Browse files- .gitignore +1 -0
- app.py +45 -11
- templates/new_person.html +35 -70
.gitignore
CHANGED
@@ -2,3 +2,4 @@
|
|
2 |
__pycache__".env"
|
3 |
".env"
|
4 |
".env"
|
|
|
|
2 |
__pycache__".env"
|
3 |
".env"
|
4 |
".env"
|
5 |
+
".env"
|
app.py
CHANGED
@@ -39,7 +39,7 @@ app.config['SECRET_KEY'] = os.urandom(24)
|
|
39 |
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
|
40 |
GOOGLE_CLIENT_ID = "228160683186-6u7986qsfhcv3kd9iqtv08iphpl4gdk2.apps.googleusercontent.com"
|
41 |
GOOGLE_CLIENT_SECRET = "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"
|
42 |
-
REDIRECT_URI = "
|
43 |
|
44 |
flow = Flow.from_client_secrets_file(
|
45 |
'client_secret.json',
|
@@ -161,6 +161,8 @@ def talk_detail():
|
|
161 |
return render_template('talkDetail.html', user=user_info)
|
162 |
|
163 |
|
|
|
|
|
164 |
# インデックス画面(テンプレート: index.html)
|
165 |
@app.route('/index', methods=['GET', 'POST'])
|
166 |
def index():
|
@@ -175,16 +177,13 @@ def index():
|
|
175 |
# 登録画面(テンプレート: new_person.html)
|
176 |
@app.route('/new_person', methods=['GET', 'POST'])
|
177 |
def new_person():
|
178 |
-
if
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
return redirect('login')
|
186 |
-
else:
|
187 |
-
return render_template('new_person.html')
|
188 |
|
189 |
@app.before_request
|
190 |
def before_request():
|
@@ -262,6 +261,41 @@ def upload_base_audio():
|
|
262 |
print("Error in /upload_base_audio:", str(e))
|
263 |
return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
|
264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
if __name__ == '__main__':
|
266 |
port = int(os.environ.get("PORT", 7860))
|
267 |
app.run(debug=True, host="0.0.0.0", port=port)
|
|
|
39 |
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
|
40 |
GOOGLE_CLIENT_ID = "228160683186-6u7986qsfhcv3kd9iqtv08iphpl4gdk2.apps.googleusercontent.com"
|
41 |
GOOGLE_CLIENT_SECRET = "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"
|
42 |
+
REDIRECT_URI = "https://huggingface.co/spaces/Justtalk/JusTalk/callbacck"
|
43 |
|
44 |
flow = Flow.from_client_secrets_file(
|
45 |
'client_secret.json',
|
|
|
161 |
return render_template('talkDetail.html', user=user_info)
|
162 |
|
163 |
|
164 |
+
|
165 |
+
|
166 |
# インデックス画面(テンプレート: index.html)
|
167 |
@app.route('/index', methods=['GET', 'POST'])
|
168 |
def index():
|
|
|
177 |
# 登録画面(テンプレート: new_person.html)
|
178 |
@app.route('/new_person', methods=['GET', 'POST'])
|
179 |
def new_person():
|
180 |
+
if 'google_id' not in session:
|
181 |
+
return redirect(url_for('login'))
|
182 |
+
user_info = {
|
183 |
+
'name': session.get('name'),
|
184 |
+
'email': session.get('email')
|
185 |
+
}
|
186 |
+
return render_template('new_person.html', user=user_info)
|
|
|
|
|
|
|
187 |
|
188 |
@app.before_request
|
189 |
def before_request():
|
|
|
261 |
print("Error in /upload_base_audio:", str(e))
|
262 |
return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
|
263 |
|
264 |
+
@app.route('/upload_audio', methods=['POST'])
|
265 |
+
def upload_audio():
|
266 |
+
try:
|
267 |
+
if 'name' not in session:
|
268 |
+
return jsonify({"error": "ユーザーが認証されていません"}), 401
|
269 |
+
|
270 |
+
data = request.get_json()
|
271 |
+
if not data or 'audio_data' not in data:
|
272 |
+
return jsonify({"error": "音声データがありません"}), 400
|
273 |
+
|
274 |
+
# Base64デコードして音声バイナリを取得
|
275 |
+
audio_binary = base64.b64decode(data['audio_data'])
|
276 |
+
|
277 |
+
# ユーザー名を取得してファイル名を作成
|
278 |
+
user_name = session['name']
|
279 |
+
sanitized_name = "".join(c for c in user_name if c.isalnum()) # 特殊文字を除去
|
280 |
+
audio_filename = f"{sanitized_name}.wav"
|
281 |
+
|
282 |
+
# 保存ディレクトリを設定
|
283 |
+
audio_dir = "record_data"
|
284 |
+
os.makedirs(audio_dir, exist_ok=True)
|
285 |
+
audio_path = os.path.join(audio_dir, audio_filename)
|
286 |
+
|
287 |
+
# 音声データをファイルに保存
|
288 |
+
with open(audio_path, 'wb') as f:
|
289 |
+
f.write(audio_binary)
|
290 |
+
|
291 |
+
print(f"音声データを {audio_path} に保存しました。")
|
292 |
+
|
293 |
+
return jsonify({"success": True, "message": f"音声が {audio_filename} に保存されました。"}), 200
|
294 |
+
except Exception as e:
|
295 |
+
print("Error in /upload_audio:", str(e))
|
296 |
+
return jsonify({"error": "サーバーエラー", "details": str(e)}), 500
|
297 |
+
|
298 |
+
|
299 |
if __name__ == '__main__':
|
300 |
port = int(os.environ.get("PORT", 7860))
|
301 |
app.run(debug=True, host="0.0.0.0", port=port)
|
templates/new_person.html
CHANGED
@@ -132,54 +132,23 @@
|
|
132 |
display: flex;
|
133 |
justify-content: center;
|
134 |
}
|
|
|
|
|
|
|
|
|
135 |
</style>
|
136 |
<title>ユーザー登録画面</title>
|
|
|
|
|
|
|
|
|
137 |
</head>
|
138 |
<body>
|
|
|
139 |
<form method="POST">
|
140 |
<div class="container">
|
141 |
-
<h2
|
142 |
<div class="flex">
|
143 |
-
<div>
|
144 |
-
<label for="">ユーザー名</label>
|
145 |
-
<br />
|
146 |
-
<input
|
147 |
-
type="text"
|
148 |
-
id="username"
|
149 |
-
name="username"
|
150 |
-
placeholder="例:技育 太郎"
|
151 |
-
required
|
152 |
-
oninput="validateForm()"
|
153 |
-
/>
|
154 |
-
<br />
|
155 |
-
<br />
|
156 |
-
<label for="">パスワード</label>
|
157 |
-
<br />
|
158 |
-
<input
|
159 |
-
type="password"
|
160 |
-
id="password"
|
161 |
-
name="password"
|
162 |
-
placeholder="半角数字8文字以上20文字以内"
|
163 |
-
maxlength="20"
|
164 |
-
required
|
165 |
-
oninput="validateForm()"
|
166 |
-
/>
|
167 |
-
<br />
|
168 |
-
<br />
|
169 |
-
<label for=""> パスワード再入力</label>
|
170 |
-
<br />
|
171 |
-
<input
|
172 |
-
type="password"
|
173 |
-
id="repassword"
|
174 |
-
name="repassword"
|
175 |
-
placeholder="再入力してください"
|
176 |
-
maxlength="20"
|
177 |
-
required
|
178 |
-
oninput="validateForm()"
|
179 |
-
/>
|
180 |
-
<p id="passwordError" class="error-message"></p>
|
181 |
-
<br />
|
182 |
-
</div>
|
183 |
<div class="new-person-right-container">
|
184 |
<label for="">
|
185 |
録音ボタンを押した後、10秒間声を録音してください</label
|
@@ -199,19 +168,18 @@
|
|
199 |
</button>
|
200 |
</div>
|
201 |
|
202 |
-
<p id="countdownDisplay"></p>
|
203 |
</div>
|
204 |
</div>
|
205 |
|
206 |
<div class="flex">
|
207 |
-
<
|
208 |
-
type="submit"
|
209 |
-
value="会員登録を行う"
|
210 |
-
name="submit"
|
211 |
-
id="submit"
|
212 |
class="history-button disabled"
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
215 |
</div>
|
216 |
</div>
|
217 |
</form>
|
@@ -299,10 +267,17 @@
|
|
299 |
})
|
300 |
.then((response) => response.json())
|
301 |
.then((data) => {
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
})
|
304 |
.catch((error) => {
|
305 |
console.error("送信エラー:", error);
|
|
|
306 |
});
|
307 |
};
|
308 |
reader.readAsDataURL(audioBlob);
|
@@ -310,28 +285,9 @@
|
|
310 |
|
311 |
// フォームの入力状態をチェック
|
312 |
function validateForm() {
|
313 |
-
const username = document.getElementById("username").value.trim();
|
314 |
-
const password = document.getElementById("password").value.trim();
|
315 |
-
const repassword = document.getElementById("repassword").value.trim();
|
316 |
const submitButton = document.getElementById("submit");
|
317 |
-
const passwordError = document.getElementById("passwordError");
|
318 |
-
|
319 |
-
if (password !== repassword) {
|
320 |
-
passwordError.textContent = "パスワードが一致しません。";
|
321 |
-
submitButton.classList.add("disabled");
|
322 |
-
submitButton.disabled = true;
|
323 |
-
return;
|
324 |
-
} else {
|
325 |
-
passwordError.textContent = "";
|
326 |
-
}
|
327 |
|
328 |
-
if (
|
329 |
-
username !== "" &&
|
330 |
-
password.length >= 8 &&
|
331 |
-
password.length <= 20 &&
|
332 |
-
password === repassword &&
|
333 |
-
isAudioRecorded
|
334 |
-
) {
|
335 |
submitButton.classList.remove("disabled");
|
336 |
submitButton.disabled = false;
|
337 |
} else {
|
@@ -339,6 +295,15 @@
|
|
339 |
submitButton.disabled = true;
|
340 |
}
|
341 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
</script>
|
343 |
</body>
|
344 |
</html>
|
|
|
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
|
|
|
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>
|
|
|
267 |
})
|
268 |
.then((response) => response.json())
|
269 |
.then((data) => {
|
270 |
+
if (data.success) {
|
271 |
+
alert("音声がサーバーに送信されました。");
|
272 |
+
isAudioRecorded = true; // サーバーからの成功レスポンスを受け取った後に設定
|
273 |
+
validateForm(); // フォームの状態を更新
|
274 |
+
} else {
|
275 |
+
alert("音声の送信に失敗しました。");
|
276 |
+
}
|
277 |
})
|
278 |
.catch((error) => {
|
279 |
console.error("送信エラー:", error);
|
280 |
+
alert("音声の送信中にエラーが発生しました。");
|
281 |
});
|
282 |
};
|
283 |
reader.readAsDataURL(audioBlob);
|
|
|
285 |
|
286 |
// フォームの入力状態をチェック
|
287 |
function validateForm() {
|
|
|
|
|
|
|
288 |
const submitButton = document.getElementById("submit");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
|
290 |
+
if (isAudioRecorded) {
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
submitButton.classList.remove("disabled");
|
292 |
submitButton.disabled = false;
|
293 |
} else {
|
|
|
295 |
submitButton.disabled = true;
|
296 |
}
|
297 |
}
|
298 |
+
|
299 |
+
// 初期化処理
|
300 |
+
displayTranscription();
|
301 |
+
|
302 |
+
//画面遷移
|
303 |
+
function showRecorder() {
|
304 |
+
// 録音画面へ遷移
|
305 |
+
window.location.href = "/index";
|
306 |
+
}
|
307 |
</script>
|
308 |
</body>
|
309 |
</html>
|