Spaces:
Paused
Paused
update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,6 @@ import torch
|
|
10 |
import re
|
11 |
import transformers
|
12 |
import spaces
|
13 |
-
import requests
|
14 |
|
15 |
# Initialize embeddings and ChromaDB
|
16 |
model_name = "sentence-transformers/all-mpnet-base-v2"
|
@@ -92,19 +91,26 @@ def chat(query, history=None):
|
|
92 |
def clear_input():
|
93 |
return "", # Return empty string to clear input field
|
94 |
|
|
|
|
|
|
|
|
|
95 |
# Gradio interface
|
96 |
with gr.Blocks() as interface:
|
97 |
gr.Markdown("## RAG Chatbot")
|
98 |
gr.Markdown("Ask a question and get answers based on retrieved documents.")
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
103 |
|
104 |
# Sign-In Button
|
105 |
login_btn = gr.Button("Sign In with HF")
|
106 |
login_btn.click(lambda: oauth_login(), outputs=None) # Redirect user for OAuth login
|
107 |
-
|
|
|
|
|
108 |
submit_btn.click(chat, inputs=[input_box, chat_history], outputs=[chat_history, input_box])
|
109 |
|
110 |
interface.launch()
|
|
|
10 |
import re
|
11 |
import transformers
|
12 |
import spaces
|
|
|
13 |
|
14 |
# Initialize embeddings and ChromaDB
|
15 |
model_name = "sentence-transformers/all-mpnet-base-v2"
|
|
|
91 |
def clear_input():
|
92 |
return "", # Return empty string to clear input field
|
93 |
|
94 |
+
# Function to show/hide components based on login status
|
95 |
+
def on_login(success):
|
96 |
+
return gr.update(visible=success), gr.update(visible=success)
|
97 |
+
|
98 |
# Gradio interface
|
99 |
with gr.Blocks() as interface:
|
100 |
gr.Markdown("## RAG Chatbot")
|
101 |
gr.Markdown("Ask a question and get answers based on retrieved documents.")
|
102 |
|
103 |
+
# Hidden components initially
|
104 |
+
input_box = gr.Textbox(label="Enter your question", placeholder="Type your question here...", visible=False)
|
105 |
+
submit_btn = gr.Button("Submit", visible=False)
|
106 |
+
chat_history = gr.Chatbot(label="Chat History", visible=False)
|
107 |
|
108 |
# Sign-In Button
|
109 |
login_btn = gr.Button("Sign In with HF")
|
110 |
login_btn.click(lambda: oauth_login(), outputs=None) # Redirect user for OAuth login
|
111 |
+
|
112 |
+
# Show components after login
|
113 |
+
submit_btn.click(on_login, inputs=[True], outputs=[input_box, submit_btn, chat_history])
|
114 |
submit_btn.click(chat, inputs=[input_box, chat_history], outputs=[chat_history, input_box])
|
115 |
|
116 |
interface.launch()
|