File size: 2,435 Bytes
095acae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87c4e69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import gradio as gr
import hashlib

# Simulated user database (in a real app, this would be a secure database)
users = {
    "admin": "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918",  # password: admin
    "user": "04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb",  # password: user
}

def hash_password(password):
    return hashlib.sha256(password.encode()).hexdigest()

def login(username, password):
    if username in users and users[username] == hash_password(password):
        return f"Welcome, {username}!"
    else:
        return "Invalid username or password."

# Create the Gradio interface
iface = gr.Interface(
    fn=login,
    inputs=[
        gr.Textbox(label="Username"),
        gr.Textbox(label="Password", type="password")
    ],
    outputs=gr.Textbox(label="Result"),
    title="Login App",
    description="Enter your username and password to log in."
)

# Launch the app
if __name__ == "__main__":
    iface.launch()
import gradio as gr
import random

# Mock user database
users = {"user1": "password1", "user2": "password2"}

def authenticate(username, password):
    if username in users and users[username] == password:
        return True
    return False

def mock_chat(message, history):
    responses = [
        "That's interesting! Tell me more.",
        "I see. How does that make you feel?",
        "Can you elaborate on that?",
        "Interesting perspective. What led you to think that way?",
        "I understand. Is there anything else on your mind?"
    ]
    return random.choice(responses)

def login(username, password):
    if authenticate(username, password):
        return gr.update(visible=False), gr.update(visible=True)
    else:
        return gr.update(visible=True), gr.update(visible=False)

with gr.Blocks() as demo:
    with gr.Group() as login_group:
        username = gr.Textbox(label="Username")
        password = gr.Textbox(label="Password", type="password")
        login_button = gr.Button("Login")

    with gr.Group(visible=False) as chat_group:
        chatbot = gr.Chatbot()
        msg = gr.Textbox()
        clear = gr.Button("Clear")

    login_button.click(
        login,
        inputs=[username, password],
        outputs=[login_group, chat_group]
    )

    msg.submit(mock_chat, [msg, chatbot], [msg, chatbot])
    clear.click(lambda: None, None, chatbot, queue=False)

if __name__ == "__main__":
    demo.launch()