Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,33 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import hashlib
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import hashlib
|
3 |
+
|
4 |
+
# Simulated user database (in a real app, this would be a secure database)
|
5 |
+
users = {
|
6 |
+
"admin": "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918", # password: admin
|
7 |
+
"user": "04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb", # password: user
|
8 |
+
}
|
9 |
+
|
10 |
+
def hash_password(password):
|
11 |
+
return hashlib.sha256(password.encode()).hexdigest()
|
12 |
+
|
13 |
+
def login(username, password):
|
14 |
+
if username in users and users[username] == hash_password(password):
|
15 |
+
return f"Welcome, {username}!"
|
16 |
+
else:
|
17 |
+
return "Invalid username or password."
|
18 |
+
|
19 |
+
# Create the Gradio interface
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=login,
|
22 |
+
inputs=[
|
23 |
+
gr.Textbox(label="Username"),
|
24 |
+
gr.Textbox(label="Password", type="password")
|
25 |
+
],
|
26 |
+
outputs=gr.Textbox(label="Result"),
|
27 |
+
title="Login App",
|
28 |
+
description="Enter your username and password to log in."
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the app
|
32 |
+
if __name__ == "__main__":
|
33 |
+
iface.launch()
|