Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,16 @@ import gradio as gr
|
|
| 4 |
from auth import register_user, login_user, logout_user, save_chats, delete_account
|
| 5 |
from response_modes import chat_stream
|
| 6 |
|
| 7 |
-
# ================== YOUR SETTINGS ==================
|
| 8 |
API_KEY = os.environ.get("API_KEY")
|
| 9 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 10 |
-
username= os.environ.get("username")
|
| 11 |
password = os.environ.get("password")
|
| 12 |
USER_DATA_REPO = "qwendashcoder/fluade_1"
|
| 13 |
|
| 14 |
if not HF_TOKEN:
|
| 15 |
raise ValueError("HF_TOKEN secret not set in HF Spaces settings!")
|
| 16 |
|
| 17 |
-
client = OpenAI(base_url="https://integrate.api.nvidia.com/v1", api_key=API_KEY)
|
| 18 |
-
|
| 19 |
auth_globals = {"hf_token": HF_TOKEN, "user_repo": USER_DATA_REPO}
|
| 20 |
|
| 21 |
model_choices = ["meta/llama-3.1-405b-instruct","meta/llama-3.1-70b-instruct","meta/llama-3.1-8b-instruct","mistralai/mistral-large-2-instruct","mistralai/mixtral-8x22b-instruct","mistralai/mistral-nemo-instruct-2407","qwen/qwen-2.5-72b-instruct","google/gemma-2-27b-it","google/gemma-2-9b-it","google/codegemma-7b-it"]
|
|
@@ -70,17 +68,17 @@ def delete_current_chat(current_title, user_chats, logged_in_username):
|
|
| 70 |
new_history = []
|
| 71 |
return new_user_chats, new_title, new_history, gr.update(choices=choices, value=new_title), f"ποΈ Deleted {current_title}"
|
| 72 |
|
| 73 |
-
# ================== GUI ==================
|
| 74 |
with gr.Blocks(title="NVIDIA AI Chat") as demo:
|
| 75 |
-
gr.Markdown("# π’ NVIDIA AI Chat\n**Multiple chats β’ Fast Search β’ Deep Think**")
|
| 76 |
gr.Markdown("Powered By AIπ€ β’ Edited/Compiled By tr0ecolor")
|
| 77 |
|
| 78 |
with gr.Accordion("π **How to Use**", open=True):
|
| 79 |
gr.Markdown("""
|
| 80 |
**Step 1:** Login / Register
|
| 81 |
**Step 2:** Load Model
|
| 82 |
-
**Step 3:** Choose
|
| 83 |
-
**Step 4:**
|
|
|
|
| 84 |
""")
|
| 85 |
|
| 86 |
current_model = gr.State(None)
|
|
@@ -108,7 +106,8 @@ with gr.Blocks(title="NVIDIA AI Chat") as demo:
|
|
| 108 |
chatbot = gr.Chatbot(height=480, buttons=["copy", "copy_all"])
|
| 109 |
|
| 110 |
with gr.Row():
|
| 111 |
-
msg = gr.Textbox(placeholder="Ask anything... (Enter or β€)", show_label=False, scale=
|
|
|
|
| 112 |
send_btn = gr.Button("β€", variant="primary", scale=1)
|
| 113 |
|
| 114 |
with gr.Row():
|
|
@@ -124,7 +123,6 @@ with gr.Blocks(title="NVIDIA AI Chat") as demo:
|
|
| 124 |
confirm_username_input = gr.Textbox(label="Type your exact username to confirm", placeholder="your_username")
|
| 125 |
confirm_delete_btn = gr.Button("YES, DELETE ACCOUNT FOREVER", variant="stop")
|
| 126 |
|
| 127 |
-
# ================== EVENTS ==================
|
| 128 |
register_btn.click(register_user, [username_input, password_input, logged_in_username, auth_globals_state],
|
| 129 |
[user_chats_state, current_chat_title, chatbot, chat_dropdown, logged_in_username, status_label, logout_btn, delete_acc_btn, confirm_row])\
|
| 130 |
.then(lambda: gr.Info("π Registration successful!", duration=4), None, None)\
|
|
@@ -151,9 +149,12 @@ with gr.Blocks(title="NVIDIA AI Chat") as demo:
|
|
| 151 |
|
| 152 |
chat_dropdown.change(switch_chat, [chat_dropdown, user_chats_state], [chatbot, current_chat_title])
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
|
|
|
| 156 |
|
| 157 |
-
send_btn.click(chat_stream, [msg, chatbot, current_model, logged_in_username, user_chats_state, current_chat_title, mode_radio, auth_globals_state], chatbot)
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
demo.launch(
|
|
|
|
| 4 |
from auth import register_user, login_user, logout_user, save_chats, delete_account
|
| 5 |
from response_modes import chat_stream
|
| 6 |
|
|
|
|
| 7 |
API_KEY = os.environ.get("API_KEY")
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 9 |
+
username = os.environ.get("username")
|
| 10 |
password = os.environ.get("password")
|
| 11 |
USER_DATA_REPO = "qwendashcoder/fluade_1"
|
| 12 |
|
| 13 |
if not HF_TOKEN:
|
| 14 |
raise ValueError("HF_TOKEN secret not set in HF Spaces settings!")
|
| 15 |
|
| 16 |
+
client = OpenAI(base_url="https://integrate.api.nvidia.com/v1", api_key=API_KEY)
|
|
|
|
| 17 |
auth_globals = {"hf_token": HF_TOKEN, "user_repo": USER_DATA_REPO}
|
| 18 |
|
| 19 |
model_choices = ["meta/llama-3.1-405b-instruct","meta/llama-3.1-70b-instruct","meta/llama-3.1-8b-instruct","mistralai/mistral-large-2-instruct","mistralai/mixtral-8x22b-instruct","mistralai/mistral-nemo-instruct-2407","qwen/qwen-2.5-72b-instruct","google/gemma-2-27b-it","google/gemma-2-9b-it","google/codegemma-7b-it"]
|
|
|
|
| 68 |
new_history = []
|
| 69 |
return new_user_chats, new_title, new_history, gr.update(choices=choices, value=new_title), f"ποΈ Deleted {current_title}"
|
| 70 |
|
|
|
|
| 71 |
with gr.Blocks(title="NVIDIA AI Chat") as demo:
|
| 72 |
+
gr.Markdown("# π’ NVIDIA AI Chat\n**Multiple chats β’ Fast Search β’ Deep Think β’ File Upload**")
|
| 73 |
gr.Markdown("Powered By AIπ€ β’ Edited/Compiled By tr0ecolor")
|
| 74 |
|
| 75 |
with gr.Accordion("π **How to Use**", open=True):
|
| 76 |
gr.Markdown("""
|
| 77 |
**Step 1:** Login / Register
|
| 78 |
**Step 2:** Load Model
|
| 79 |
+
**Step 3:** Choose Response Mode
|
| 80 |
+
**Step 4:** (Optional) Attach .txt / .pdf / .docx
|
| 81 |
+
**Step 5:** Type message β Send
|
| 82 |
""")
|
| 83 |
|
| 84 |
current_model = gr.State(None)
|
|
|
|
| 106 |
chatbot = gr.Chatbot(height=480, buttons=["copy", "copy_all"])
|
| 107 |
|
| 108 |
with gr.Row():
|
| 109 |
+
msg = gr.Textbox(placeholder="Ask anything... (Enter or β€)", show_label=False, scale=8)
|
| 110 |
+
file_upload = gr.File(label="Attach (.txt/.pdf/.docx)", file_types=[".txt", ".pdf", ".docx"], scale=2)
|
| 111 |
send_btn = gr.Button("β€", variant="primary", scale=1)
|
| 112 |
|
| 113 |
with gr.Row():
|
|
|
|
| 123 |
confirm_username_input = gr.Textbox(label="Type your exact username to confirm", placeholder="your_username")
|
| 124 |
confirm_delete_btn = gr.Button("YES, DELETE ACCOUNT FOREVER", variant="stop")
|
| 125 |
|
|
|
|
| 126 |
register_btn.click(register_user, [username_input, password_input, logged_in_username, auth_globals_state],
|
| 127 |
[user_chats_state, current_chat_title, chatbot, chat_dropdown, logged_in_username, status_label, logout_btn, delete_acc_btn, confirm_row])\
|
| 128 |
.then(lambda: gr.Info("π Registration successful!", duration=4), None, None)\
|
|
|
|
| 149 |
|
| 150 |
chat_dropdown.change(switch_chat, [chat_dropdown, user_chats_state], [chatbot, current_chat_title])
|
| 151 |
|
| 152 |
+
msg.submit(chat_stream, [msg, chatbot, current_model, logged_in_username, user_chats_state, current_chat_title, mode_radio, auth_globals_state, file_upload], chatbot)\
|
| 153 |
+
.then(lambda: "", None, msg)\
|
| 154 |
+
.then(lambda: None, None, file_upload)
|
| 155 |
|
| 156 |
+
send_btn.click(chat_stream, [msg, chatbot, current_model, logged_in_username, user_chats_state, current_chat_title, mode_radio, auth_globals_state, file_upload], chatbot)\
|
| 157 |
+
.then(lambda: "", None, msg)\
|
| 158 |
+
.then(lambda: None, None, file_upload)
|
| 159 |
|
| 160 |
+
demo.launch(theme=gr.themes.Soft(), ssr_mode=False, show_error=True)
|