Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,6 +64,108 @@ def delete_current_chat(current_title, user_chats, logged_in_username):
|
|
| 64 |
return new_user_chats, new_title, new_history, gr.update(choices=choices, value=new_title), f"ποΈ Deleted {current_title}"
|
| 65 |
|
| 66 |
# ================== GUI ==================
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
demo.launch(auth=(username,password),theme=gr.themes.Soft(), ssr_mode=False, show_error=True)
|
|
|
|
| 64 |
return new_user_chats, new_title, new_history, gr.update(choices=choices, value=new_title), f"ποΈ Deleted {current_title}"
|
| 65 |
|
| 66 |
# ================== GUI ==================
|
| 67 |
+
with gr.Blocks(title="NVIDIA AI Chat") as demo:
|
| 68 |
+
gr.Markdown("# π’ NVIDIA AI Chat\n**School Project β’ Pre-approved usernames only β’ Max 20 Accounts globally**")
|
| 69 |
+
gr.Markdown(f"{mymsg.welcome_caution()}")
|
| 70 |
+
|
| 71 |
+
with gr.Accordion("π How to Use", open=True):
|
| 72 |
+
gr.Markdown(f"mymsg.welcome_message[0]")
|
| 73 |
+
|
| 74 |
+
current_model = gr.State(None)
|
| 75 |
+
logged_in_username = gr.State(None)
|
| 76 |
+
user_chats_state = gr.State([])
|
| 77 |
+
current_chat_title = gr.State(None)
|
| 78 |
+
auth_globals_state = gr.State(auth_globals)
|
| 79 |
+
|
| 80 |
+
status_label = gr.Markdown("β οΈ No model loaded. Login + create/select a chat to begin.")
|
| 81 |
+
|
| 82 |
+
with gr.Row():
|
| 83 |
+
with gr.Column(scale=1, min_width=200):
|
| 84 |
+
gr.Markdown("### π Your Chats")
|
| 85 |
+
new_chat_btn = gr.Button("β New Chat", variant="primary", size="large")
|
| 86 |
+
delete_chat_btn = gr.Button("ποΈ Delete Current", variant="stop", size="large")
|
| 87 |
+
chat_dropdown = gr.Dropdown(choices=[], label="Switch Chat", interactive=True, value=None)
|
| 88 |
+
|
| 89 |
+
with gr.Column(scale=4):
|
| 90 |
+
with gr.Row():
|
| 91 |
+
model_dropdown = gr.Dropdown(choices=model_choices, value=model_choices[0], label="π― Select Model", interactive=True, scale=4)
|
| 92 |
+
load_btn = gr.Button("Load & Test Model", variant="primary", scale=1)
|
| 93 |
+
|
| 94 |
+
mode_radio = gr.Radio(
|
| 95 |
+
choices=["Default Chat", "Fast Search", "Deep Think", "π» Coding Mode"],
|
| 96 |
+
value="Default Chat",
|
| 97 |
+
label="π§ Response Mode",
|
| 98 |
+
interactive=True
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
chatbot = gr.Chatbot(height=480, buttons=["copy", "copy_all"])
|
| 102 |
+
|
| 103 |
+
with gr.Row():
|
| 104 |
+
msg = gr.Textbox(placeholder="Ask anything...", show_label=False, scale=9)
|
| 105 |
+
file_upload = gr.File(
|
| 106 |
+
label="Attach up to 5 files (.txt, .pdf, .docx)",
|
| 107 |
+
file_types=[".txt", ".pdf", ".docx"],
|
| 108 |
+
file_count="multiple",
|
| 109 |
+
type="filepath"
|
| 110 |
+
)
|
| 111 |
+
send_btn = gr.Button("β€", variant="primary", scale=1)
|
| 112 |
+
|
| 113 |
+
# Authentication (clean version - no phone/OTP)
|
| 114 |
+
with gr.Row():
|
| 115 |
+
username_input = gr.Textbox(label="Username (will be forced lowercase)", scale=2, placeholder="admin")
|
| 116 |
+
password_input = gr.Textbox(label="Password", type="password", scale=2)
|
| 117 |
+
|
| 118 |
+
with gr.Row():
|
| 119 |
+
register_btn = gr.Button("Register", variant="secondary")
|
| 120 |
+
login_btn = gr.Button("Login", variant="primary")
|
| 121 |
+
logout_btn = gr.Button("Logout", visible=False, variant="stop")
|
| 122 |
+
|
| 123 |
+
with gr.Accordion("β οΈ Danger Zone", open=False):
|
| 124 |
+
delete_acc_btn = gr.Button("ποΈ Delete My Account", variant="stop", size="large", visible=False)
|
| 125 |
+
with gr.Row(visible=False) as confirm_row:
|
| 126 |
+
confirm_username_input = gr.Textbox(label="Type exact username to confirm", placeholder="yourusername")
|
| 127 |
+
confirm_delete_btn = gr.Button("YES, DELETE FOREVER", variant="stop")
|
| 128 |
+
|
| 129 |
+
# ================== EVENTS ==================
|
| 130 |
+
load_btn.click(load_model, model_dropdown, [current_model, status_label])
|
| 131 |
+
|
| 132 |
+
new_chat_btn.click(create_new_chat, [user_chats_state, logged_in_username], [user_chats_state, current_chat_title, chatbot, chat_dropdown, status_label])
|
| 133 |
+
|
| 134 |
+
delete_chat_btn.click(delete_current_chat, [current_chat_title, user_chats_state, logged_in_username],
|
| 135 |
+
[user_chats_state, current_chat_title, chatbot, chat_dropdown, status_label])
|
| 136 |
+
|
| 137 |
+
chat_dropdown.change(switch_chat, [chat_dropdown, user_chats_state], [chatbot, current_chat_title])
|
| 138 |
+
|
| 139 |
+
register_btn.click(
|
| 140 |
+
register_user,
|
| 141 |
+
[username_input, password_input, logged_in_username, auth_globals_state],
|
| 142 |
+
[user_chats_state, current_chat_title, chatbot, chat_dropdown, logged_in_username, status_label, logout_btn, delete_acc_btn, confirm_row]
|
| 143 |
+
).then(lambda: gr.Info("β
Registration successful!", duration=4), None, None)\
|
| 144 |
+
.then(lambda: ("",""), None, [username_input, password_input])
|
| 145 |
+
|
| 146 |
+
login_btn.click(
|
| 147 |
+
login_user,
|
| 148 |
+
[username_input, password_input, logged_in_username, auth_globals_state],
|
| 149 |
+
[user_chats_state, current_chat_title, chatbot, chat_dropdown, logged_in_username, status_label, logout_btn, delete_acc_btn, confirm_row]
|
| 150 |
+
).then(lambda: gr.Info("β
Login successful!", duration=4), None, None)\
|
| 151 |
+
.then(lambda: ("",""), None, [username_input, password_input])
|
| 152 |
+
|
| 153 |
+
logout_btn.click(logout_user, [], [user_chats_state, current_chat_title, chatbot, chat_dropdown, logged_in_username, status_label, logout_btn, delete_acc_btn, confirm_row])
|
| 154 |
+
|
| 155 |
+
delete_acc_btn.click(lambda: gr.update(visible=True), None, confirm_row)
|
| 156 |
+
confirm_delete_btn.click(delete_account, [confirm_username_input, logged_in_username, auth_globals_state],
|
| 157 |
+
[status_label, logged_in_username, logout_btn, delete_acc_btn, confirm_row, user_chats_state, current_chat_title, chatbot, chat_dropdown])
|
| 158 |
+
|
| 159 |
+
msg.submit(
|
| 160 |
+
chat_stream,
|
| 161 |
+
[msg, chatbot, current_model, logged_in_username, user_chats_state, current_chat_title, mode_radio, auth_globals_state, file_upload],
|
| 162 |
+
chatbot
|
| 163 |
+
).then(lambda: "", None, msg)
|
| 164 |
+
|
| 165 |
+
send_btn.click(
|
| 166 |
+
chat_stream,
|
| 167 |
+
[msg, chatbot, current_model, logged_in_username, user_chats_state, current_chat_title, mode_radio, auth_globals_state, file_upload],
|
| 168 |
+
chatbot
|
| 169 |
+
).then(lambda: "", None, msg)
|
| 170 |
|
| 171 |
demo.launch(auth=(username,password),theme=gr.themes.Soft(), ssr_mode=False, show_error=True)
|