mrgalindo commited on
Commit
87c4e69
1 Parent(s): 095acae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py CHANGED
@@ -31,3 +31,52 @@ iface = gr.Interface(
31
  # Launch the app
32
  if __name__ == "__main__":
33
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # Launch the app
32
  if __name__ == "__main__":
33
  iface.launch()
34
+ import gradio as gr
35
+ import random
36
+
37
+ # Mock user database
38
+ users = {"user1": "password1", "user2": "password2"}
39
+
40
+ def authenticate(username, password):
41
+ if username in users and users[username] == password:
42
+ return True
43
+ return False
44
+
45
+ def mock_chat(message, history):
46
+ responses = [
47
+ "That's interesting! Tell me more.",
48
+ "I see. How does that make you feel?",
49
+ "Can you elaborate on that?",
50
+ "Interesting perspective. What led you to think that way?",
51
+ "I understand. Is there anything else on your mind?"
52
+ ]
53
+ return random.choice(responses)
54
+
55
+ def login(username, password):
56
+ if authenticate(username, password):
57
+ return gr.update(visible=False), gr.update(visible=True)
58
+ else:
59
+ return gr.update(visible=True), gr.update(visible=False)
60
+
61
+ with gr.Blocks() as demo:
62
+ with gr.Group() as login_group:
63
+ username = gr.Textbox(label="Username")
64
+ password = gr.Textbox(label="Password", type="password")
65
+ login_button = gr.Button("Login")
66
+
67
+ with gr.Group(visible=False) as chat_group:
68
+ chatbot = gr.Chatbot()
69
+ msg = gr.Textbox()
70
+ clear = gr.Button("Clear")
71
+
72
+ login_button.click(
73
+ login,
74
+ inputs=[username, password],
75
+ outputs=[login_group, chat_group]
76
+ )
77
+
78
+ msg.submit(mock_chat, [msg, chatbot], [msg, chatbot])
79
+ clear.click(lambda: None, None, chatbot, queue=False)
80
+
81
+ if __name__ == "__main__":
82
+ demo.launch()