Spaces:
Paused
Paused
update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import requests
|
|
| 3 |
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'
|
|
@@ -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 |
-
lock = threading.Lock() # Create a lock
|
| 18 |
|
| 19 |
class RequestHandler(BaseHTTPRequestHandler):
|
| 20 |
def do_GET(self):
|
| 21 |
global access_token
|
| 22 |
if self.path.startswith("/callback"):
|
|
|
|
| 23 |
code = self.path.split("code=")[1].split("&")[0]
|
| 24 |
response = requests.post(TOKEN_URL, data={
|
| 25 |
'client_id': CLIENT_ID,
|
|
@@ -29,8 +28,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|
| 29 |
'redirect_uri': REDIRECT_URI
|
| 30 |
})
|
| 31 |
token_data = response.json()
|
| 32 |
-
|
| 33 |
-
access_token = token_data.get('access_token')
|
| 34 |
self.send_response(200)
|
| 35 |
self.end_headers()
|
| 36 |
self.wfile.write(b"Login successful! You can close this window.")
|
|
@@ -55,7 +53,6 @@ def handle_login_click():
|
|
| 55 |
login()
|
| 56 |
return "Please complete the login process in the opened window."
|
| 57 |
|
| 58 |
-
@spaces.GPU(duration=60)
|
| 59 |
def gradio_interface():
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("### Welcome to the App")
|
|
@@ -67,7 +64,7 @@ def gradio_interface():
|
|
| 67 |
return demo
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
# Start the HTTP server in
|
| 71 |
threading.Thread(target=start_http_server, daemon=True).start()
|
| 72 |
|
| 73 |
# Launch Gradio app
|
|
|
|
| 3 |
import webbrowser
|
| 4 |
from http.server import BaseHTTPRequestHandler, HTTPServer
|
| 5 |
import threading
|
|
|
|
| 6 |
|
| 7 |
# OAuth Configuration
|
| 8 |
TENANT_ID = '2b093ced-2571-463f-bc3e-b4f8bcb427ee'
|
|
|
|
| 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 # Global access token
|
|
|
|
| 16 |
|
| 17 |
class RequestHandler(BaseHTTPRequestHandler):
|
| 18 |
def do_GET(self):
|
| 19 |
global access_token
|
| 20 |
if self.path.startswith("/callback"):
|
| 21 |
+
# Capture the authorization code
|
| 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 |
+
access_token = token_data.get('access_token')
|
|
|
|
| 32 |
self.send_response(200)
|
| 33 |
self.end_headers()
|
| 34 |
self.wfile.write(b"Login successful! You can close this window.")
|
|
|
|
| 53 |
login()
|
| 54 |
return "Please complete the login process in the opened window."
|
| 55 |
|
|
|
|
| 56 |
def gradio_interface():
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
gr.Markdown("### Welcome to the App")
|
|
|
|
| 64 |
return demo
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
# Start the HTTP server in a separate thread
|
| 68 |
threading.Thread(target=start_http_server, daemon=True).start()
|
| 69 |
|
| 70 |
# Launch Gradio app
|