sanjeevbora commited on
Commit
21340af
·
verified ·
1 Parent(s): fe10fad
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -153,32 +153,28 @@ def chat_interface():
153
 
154
  return interface
155
 
156
- # Function to handle OAuth callback and extract authorization code
157
- def handle_auth_callback(query_params):
158
  global access_token
159
 
160
- # Parse the query parameters to extract the authorization code
161
- parsed_url = urlparse(query_params)
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
- # Check for the authentication callback
175
- app_url = spaces.get_url()
176
- if app_url.startswith(REDIRECT_URI):
177
- query_params = app_url.split('?')[-1]
178
- handle_auth_callback(query_params)
 
 
 
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()