Spaces:
Paused
Paused
auth
Browse files
app.py
CHANGED
|
@@ -153,32 +153,28 @@ def chat_interface():
|
|
| 153 |
|
| 154 |
return interface
|
| 155 |
|
| 156 |
-
# Function to handle OAuth callback
|
| 157 |
-
def handle_auth_callback(
|
| 158 |
global access_token
|
| 159 |
|
| 160 |
-
#
|
| 161 |
-
|
| 162 |
-
query_dict = parse_qs(parsed_url.query)
|
| 163 |
-
|
| 164 |
-
if 'code' in query_dict:
|
| 165 |
-
auth_code = query_dict['code'][0]
|
| 166 |
-
access_token = exchange_code_for_token(auth_code)
|
| 167 |
-
|
| 168 |
return "Authentication successful. You can now use the chatbot."
|
| 169 |
|
| 170 |
# Gradio app launch
|
| 171 |
with gr.Blocks() as app:
|
| 172 |
gr.Markdown("## OAuth2.0 Chatbot")
|
| 173 |
|
| 174 |
-
#
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
# Display the chat interface or authentication prompt
|
| 181 |
chat_interface()
|
| 182 |
|
| 183 |
-
app.launch()
|
| 184 |
-
|
|
|
|
| 153 |
|
| 154 |
return interface
|
| 155 |
|
| 156 |
+
# Function to handle OAuth callback
|
| 157 |
+
def handle_auth_callback(auth_code):
|
| 158 |
global access_token
|
| 159 |
|
| 160 |
+
# Exchange authorization code for access token
|
| 161 |
+
access_token = exchange_code_for_token(auth_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
return "Authentication successful. You can now use the chatbot."
|
| 163 |
|
| 164 |
# Gradio app launch
|
| 165 |
with gr.Blocks() as app:
|
| 166 |
gr.Markdown("## OAuth2.0 Chatbot")
|
| 167 |
|
| 168 |
+
# Add an input field to manually input the authorization code for testing
|
| 169 |
+
auth_code_input = gr.Textbox(label="Enter the OAuth Authorization Code")
|
| 170 |
+
|
| 171 |
+
# Button to handle authentication and exchange the code for the access token
|
| 172 |
+
auth_button = gr.Button("Authenticate")
|
| 173 |
+
|
| 174 |
+
# Callback for authentication
|
| 175 |
+
auth_button.click(fn=handle_auth_callback, inputs=auth_code_input, outputs="text")
|
| 176 |
|
| 177 |
# Display the chat interface or authentication prompt
|
| 178 |
chat_interface()
|
| 179 |
|
| 180 |
+
app.launch()
|
|
|