Spaces:
Paused
Paused
updated app.py
Browse files
app.py
CHANGED
@@ -4,22 +4,23 @@ import webbrowser
|
|
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'
|
10 |
CLIENT_SECRET = 'EOF8Q~kKHCRgx8tnlLM-H8e93ifetxI6x7sU6bGW'
|
11 |
-
REDIRECT_URI = 'https://sanjeevbora-chatbot.hf.space/
|
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 |
-
|
|
|
23 |
response = requests.post(TOKEN_URL, data={
|
24 |
'client_id': CLIENT_ID,
|
25 |
'client_secret': CLIENT_SECRET,
|
@@ -28,8 +29,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|
28 |
'redirect_uri': REDIRECT_URI
|
29 |
})
|
30 |
token_data = response.json()
|
31 |
-
|
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.")
|
@@ -52,21 +52,20 @@ def check_login():
|
|
52 |
|
53 |
def handle_login_click():
|
54 |
login()
|
55 |
-
return
|
56 |
-
|
57 |
@spaces.GPU(duration=60)
|
58 |
def gradio_interface():
|
59 |
with gr.Blocks() as demo:
|
60 |
gr.Markdown("### Welcome to the App")
|
61 |
btn_login = gr.Button("Login with Microsoft")
|
62 |
-
output = gr.Textbox(label="Status"
|
63 |
|
64 |
btn_login.click(handle_login_click, None, output)
|
65 |
|
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 |
+
|
8 |
# OAuth Configuration
|
9 |
TENANT_ID = '2b093ced-2571-463f-bc3e-b4f8bcb427ee'
|
10 |
CLIENT_ID = '2a7c884c-942d-49e2-9e5d-7a29d8a0d3e5'
|
11 |
CLIENT_SECRET = 'EOF8Q~kKHCRgx8tnlLM-H8e93ifetxI6x7sU6bGW'
|
12 |
+
REDIRECT_URI = 'https://sanjeevbora-chatbot.hf.space/'
|
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]
|
24 |
response = requests.post(TOKEN_URL, data={
|
25 |
'client_id': CLIENT_ID,
|
26 |
'client_secret': CLIENT_SECRET,
|
|
|
29 |
'redirect_uri': REDIRECT_URI
|
30 |
})
|
31 |
token_data = response.json()
|
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.")
|
|
|
52 |
|
53 |
def handle_login_click():
|
54 |
login()
|
55 |
+
return check_login()
|
|
|
56 |
@spaces.GPU(duration=60)
|
57 |
def gradio_interface():
|
58 |
with gr.Blocks() as demo:
|
59 |
gr.Markdown("### Welcome to the App")
|
60 |
btn_login = gr.Button("Login with Microsoft")
|
61 |
+
output = gr.Textbox(label="Status")
|
62 |
|
63 |
btn_login.click(handle_login_click, None, output)
|
64 |
|
65 |
return demo
|
66 |
|
67 |
if __name__ == "__main__":
|
68 |
+
# Start the HTTP server in a separate thread
|
69 |
threading.Thread(target=start_http_server, daemon=True).start()
|
70 |
|
71 |
# Launch Gradio app
|