Trung commited on
Commit
b360f11
·
1 Parent(s): 0b499c1

Update space

Browse files
Files changed (1) hide show
  1. app.py +52 -19
app.py CHANGED
@@ -1,6 +1,11 @@
1
  import gradio as gr
 
2
  from huggingface_hub import InferenceClient
3
 
 
 
 
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
  """
@@ -40,25 +45,53 @@ def respond(
40
  yield response
41
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
- ],
60
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
 
63
  if __name__ == "__main__":
64
- demo.launch()
 
1
  import gradio as gr
2
+ import os
3
  from huggingface_hub import InferenceClient
4
 
5
+ # Password authentication setup
6
+ PASSWORD = os.environ.get("APP_PASSWORD", "default_password") # Get from Space secrets
7
+ authenticated = False # Track authentication state
8
+
9
  """
10
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
11
  """
 
45
  yield response
46
 
47
 
48
+ def check_password(password_attempt):
49
+ if password_attempt == PASSWORD:
50
+ return True, "Login successful! Redirecting to chat..."
51
+ else:
52
+ return False, "Incorrect password. Please try again."
53
+
54
+
55
+ # Authentication interface
56
+ with gr.Blocks() as login_interface:
57
+ gr.Markdown("## Authentication Required")
58
+ gr.Markdown("Please enter the password to access this application.")
59
+ password_input = gr.Textbox(type="password", label="Password")
60
+ login_button = gr.Button("Login")
61
+ result = gr.Markdown()
62
+
63
+ # Chat interface (initially hidden)
64
+ with gr.Accordion("Chat", visible=False) as chat_accordion:
65
+ chat_interface = gr.ChatInterface(
66
+ respond,
67
+ additional_inputs=[
68
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
69
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
70
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
71
+ gr.Slider(
72
+ minimum=0.1,
73
+ maximum=1.0,
74
+ value=0.95,
75
+ step=0.05,
76
+ label="Top-p (nucleus sampling)",
77
+ ),
78
+ ],
79
+ )
80
+
81
+ # Login logic
82
+ def handle_login(password):
83
+ success, message = check_password(password)
84
+ if success:
85
+ return message, gr.update(visible=True), gr.update(visible=False)
86
+ else:
87
+ return message, gr.update(visible=False), gr.update(visible=True)
88
+
89
+ login_button.click(
90
+ handle_login,
91
+ inputs=[password_input],
92
+ outputs=[result, chat_accordion, password_input],
93
+ )
94
 
95
 
96
  if __name__ == "__main__":
97
+ login_interface.launch()