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()