Spaces:
Paused
Paused
updated app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import webbrowser
|
|
4 |
from http.server import BaseHTTPRequestHandler, HTTPServer
|
5 |
import threading
|
6 |
import spaces
|
7 |
-
|
8 |
# OAuth Configuration
|
9 |
TENANT_ID = '2b093ced-2571-463f-bc3e-b4f8bcb427ee'
|
10 |
CLIENT_ID = '2a7c884c-942d-49e2-9e5d-7a29d8a0d3e5'
|
@@ -13,13 +12,13 @@ REDIRECT_URI = 'https://sanjeevbora-chatbot.hf.space/callback'
|
|
13 |
AUTH_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize"
|
14 |
TOKEN_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
|
15 |
SCOPE = 'User.Read'
|
16 |
-
access_token = None
|
|
|
17 |
|
18 |
class RequestHandler(BaseHTTPRequestHandler):
|
19 |
def do_GET(self):
|
20 |
global access_token
|
21 |
if self.path.startswith("/callback"):
|
22 |
-
# Capture the authorization code
|
23 |
code = self.path.split("code=")[1].split("&")[0]
|
24 |
response = requests.post(TOKEN_URL, data={
|
25 |
'client_id': CLIENT_ID,
|
@@ -29,7 +28,8 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|
29 |
'redirect_uri': REDIRECT_URI
|
30 |
})
|
31 |
token_data = response.json()
|
32 |
-
|
|
|
33 |
self.send_response(200)
|
34 |
self.end_headers()
|
35 |
self.wfile.write(b"Login successful! You can close this window.")
|
@@ -53,7 +53,7 @@ def check_login():
|
|
53 |
def handle_login_click():
|
54 |
login()
|
55 |
return "Please complete the login process in the opened window."
|
56 |
-
|
57 |
@spaces.GPU(duration=60)
|
58 |
def gradio_interface():
|
59 |
with gr.Blocks() as demo:
|
@@ -66,7 +66,7 @@ def gradio_interface():
|
|
66 |
return demo
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
-
# Start the HTTP server in
|
70 |
threading.Thread(target=start_http_server, daemon=True).start()
|
71 |
|
72 |
# Launch Gradio app
|
|
|
4 |
from http.server import BaseHTTPRequestHandler, HTTPServer
|
5 |
import threading
|
6 |
import spaces
|
|
|
7 |
# OAuth Configuration
|
8 |
TENANT_ID = '2b093ced-2571-463f-bc3e-b4f8bcb427ee'
|
9 |
CLIENT_ID = '2a7c884c-942d-49e2-9e5d-7a29d8a0d3e5'
|
|
|
12 |
AUTH_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/authorize"
|
13 |
TOKEN_URL = f"https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token"
|
14 |
SCOPE = 'User.Read'
|
15 |
+
access_token = None
|
16 |
+
lock = threading.Lock() # Create a lock
|
17 |
|
18 |
class RequestHandler(BaseHTTPRequestHandler):
|
19 |
def do_GET(self):
|
20 |
global access_token
|
21 |
if self.path.startswith("/callback"):
|
|
|
22 |
code = self.path.split("code=")[1].split("&")[0]
|
23 |
response = requests.post(TOKEN_URL, data={
|
24 |
'client_id': CLIENT_ID,
|
|
|
28 |
'redirect_uri': REDIRECT_URI
|
29 |
})
|
30 |
token_data = response.json()
|
31 |
+
with lock: # Lock access to the token
|
32 |
+
access_token = token_data.get('access_token')
|
33 |
self.send_response(200)
|
34 |
self.end_headers()
|
35 |
self.wfile.write(b"Login successful! You can close this window.")
|
|
|
53 |
def handle_login_click():
|
54 |
login()
|
55 |
return "Please complete the login process in the opened window."
|
56 |
+
|
57 |
@spaces.GPU(duration=60)
|
58 |
def gradio_interface():
|
59 |
with gr.Blocks() as demo:
|
|
|
66 |
return demo
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
+
# Start the HTTP server in the main thread
|
70 |
threading.Thread(target=start_http_server, daemon=True).start()
|
71 |
|
72 |
# Launch Gradio app
|