Subbu1304 commited on
Commit
d1432ce
·
verified ·
1 Parent(s): 84ba0a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -45
app.py CHANGED
@@ -1,50 +1,36 @@
1
- import gradio as gr
2
- import speech_recognition as sr
3
- import pyttsx3
4
-
5
- def speak_text(text):
6
- engine = pyttsx3.init()
7
- engine.say(text)
8
- engine.runAndWait()
9
-
10
- def recognize_speech():
11
- recognizer = sr.Recognizer()
12
- with sr.Microphone() as source:
13
- speak_text("Please say your name.")
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
- audio = recognizer.listen(source)
23
- confirmation = recognizer.recognize_google(audio)
24
- if confirmation.lower() == "yes":
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 "Name confirmation failed. Try again."
 
 
 
 
 
 
 
 
40
 
41
- gui = gr.Interface(
42
- fn=recognize_speech,
43
- inputs=[],
44
- outputs="text",
45
- title="Voice Assisted Login System",
46
- description="Speak your name and email to log in."
47
- )
48
 
49
- gui.launch()
 
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