Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,36 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
recognizer.adjust_for_ambient_noise(source)
|
| 15 |
-
audio = recognizer.listen(source)
|
| 16 |
-
try:
|
| 17 |
-
name = recognizer.recognize_google(audio)
|
| 18 |
-
speak_text(f"You said {name}. Please confirm by saying Yes or No.")
|
| 19 |
-
except sr.UnknownValueError:
|
| 20 |
-
return "Sorry, could not understand. Try again."
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
speak_text("Now, please say your email address.")
|
| 26 |
-
audio = recognizer.listen(source)
|
| 27 |
-
try:
|
| 28 |
-
email = recognizer.recognize_google(audio)
|
| 29 |
-
speak_text(f"You said {email}. Please confirm by saying Yes or No.")
|
| 30 |
-
audio = recognizer.listen(source)
|
| 31 |
-
email_confirm = recognizer.recognize_google(audio)
|
| 32 |
-
if email_confirm.lower() == "yes":
|
| 33 |
-
return f"Login successful. Welcome {name}! Your email is {email}."
|
| 34 |
-
else:
|
| 35 |
-
return "Email confirmation failed. Try again."
|
| 36 |
-
except sr.UnknownValueError:
|
| 37 |
-
return "Could not recognize email. Try again."
|
| 38 |
else:
|
| 39 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
title="Voice Assisted Login System",
|
| 46 |
-
description="Speak your name and email to log in."
|
| 47 |
-
)
|
| 48 |
|
| 49 |
-
|
|
|
|
| 50 |
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, redirect, url_for, session
|
| 2 |
+
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
app.secret_key = "your_secret_key"
|
| 5 |
+
|
| 6 |
+
# Dummy user credentials
|
| 7 |
+
USER_CREDENTIALS = {"admin": "password123"}
|
| 8 |
+
|
| 9 |
+
@app.route("/", methods=["GET", "POST"])
|
| 10 |
+
def login():
|
| 11 |
+
if request.method == "POST":
|
| 12 |
+
username = request.form["username"]
|
| 13 |
+
password = request.form["password"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
if username in USER_CREDENTIALS and USER_CREDENTIALS[username] == password:
|
| 16 |
+
session["user"] = username
|
| 17 |
+
return redirect(url_for("dashboard"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
else:
|
| 19 |
+
return render_template("login.html", error="Invalid Credentials")
|
| 20 |
+
|
| 21 |
+
return render_template("login.html", error=None)
|
| 22 |
+
|
| 23 |
+
@app.route("/dashboard")
|
| 24 |
+
def dashboard():
|
| 25 |
+
if "user" in session:
|
| 26 |
+
return f"Welcome, {session['user']}! <a href='/logout'>Logout</a>"
|
| 27 |
+
return redirect(url_for("login"))
|
| 28 |
|
| 29 |
+
@app.route("/logout")
|
| 30 |
+
def logout():
|
| 31 |
+
session.pop("user", None)
|
| 32 |
+
return redirect(url_for("login"))
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
app.run(debug=True)
|
| 36 |
|