Spaces:
Paused
Paused
auth
Browse files
app.py
CHANGED
|
@@ -123,8 +123,7 @@ def exchange_code_for_token(auth_code):
|
|
| 123 |
if response.status_code == 200:
|
| 124 |
token_data = response.json()
|
| 125 |
return token_data.get('access_token')
|
| 126 |
-
|
| 127 |
-
return None
|
| 128 |
|
| 129 |
def handle_redirect(auth_code):
|
| 130 |
token = exchange_code_for_token(auth_code)
|
|
@@ -174,7 +173,6 @@ with gr.Blocks() as interface:
|
|
| 174 |
gr.Markdown("## RAG Chatbot")
|
| 175 |
gr.Markdown("Please log in to continue.")
|
| 176 |
|
| 177 |
-
login_link = gr.HTML(show_login_button())
|
| 178 |
login_status = gr.Textbox(label="Login Status", visible=False)
|
| 179 |
|
| 180 |
# Components for chat (initially hidden)
|
|
@@ -182,11 +180,13 @@ with gr.Blocks() as interface:
|
|
| 182 |
submit_btn = gr.Button("Submit", visible=False)
|
| 183 |
chat_history = gr.Chatbot(label="Chat History", visible=False)
|
| 184 |
|
| 185 |
-
#
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
-
#
|
| 189 |
-
@gr.Interface().on_submit
|
| 190 |
def on_redirect(url):
|
| 191 |
# Extract the authorization code from the URL
|
| 192 |
parsed_url = urlparse(url)
|
|
@@ -197,9 +197,10 @@ with gr.Blocks() as interface:
|
|
| 197 |
if handle_redirect(auth_code[0]): # Pass the first code if there are multiple
|
| 198 |
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 199 |
else:
|
| 200 |
-
|
| 201 |
-
|
| 202 |
# Input submission and chat handling
|
| 203 |
submit_btn.click(chat, inputs=[input_box, chat_history], outputs=[chat_history, input_box])
|
| 204 |
|
|
|
|
| 205 |
interface.launch()
|
|
|
|
| 123 |
if response.status_code == 200:
|
| 124 |
token_data = response.json()
|
| 125 |
return token_data.get('access_token')
|
| 126 |
+
return None
|
|
|
|
| 127 |
|
| 128 |
def handle_redirect(auth_code):
|
| 129 |
token = exchange_code_for_token(auth_code)
|
|
|
|
| 173 |
gr.Markdown("## RAG Chatbot")
|
| 174 |
gr.Markdown("Please log in to continue.")
|
| 175 |
|
|
|
|
| 176 |
login_status = gr.Textbox(label="Login Status", visible=False)
|
| 177 |
|
| 178 |
# Components for chat (initially hidden)
|
|
|
|
| 180 |
submit_btn = gr.Button("Submit", visible=False)
|
| 181 |
chat_history = gr.Chatbot(label="Chat History", visible=False)
|
| 182 |
|
| 183 |
+
# Button for login
|
| 184 |
+
login_button = gr.Button("Click here to login with Microsoft")
|
| 185 |
+
|
| 186 |
+
# Handle the login button click
|
| 187 |
+
login_button.click(lambda: gr.update(visible=False), inputs=[], outputs=[login_button])
|
| 188 |
|
| 189 |
+
# Function to handle the redirect
|
|
|
|
| 190 |
def on_redirect(url):
|
| 191 |
# Extract the authorization code from the URL
|
| 192 |
parsed_url = urlparse(url)
|
|
|
|
| 197 |
if handle_redirect(auth_code[0]): # Pass the first code if there are multiple
|
| 198 |
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 199 |
else:
|
| 200 |
+
return gr.update(value="Login failed."), # Show failure message
|
| 201 |
+
|
| 202 |
# Input submission and chat handling
|
| 203 |
submit_btn.click(chat, inputs=[input_box, chat_history], outputs=[chat_history, input_box])
|
| 204 |
|
| 205 |
+
# Add an event listener to check for redirects in the Gradio interface (this might require running an additional server)
|
| 206 |
interface.launch()
|