Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import pandas as pd
|
4 |
-
from azure.identity import
|
5 |
from azure.mgmt.resource import ResourceManagementClient
|
6 |
from azure.cosmos import CosmosClient, exceptions
|
7 |
from github import Github
|
@@ -9,12 +9,42 @@ from git import Repo
|
|
9 |
import shutil
|
10 |
from datetime import datetime
|
11 |
import base64
|
|
|
|
|
12 |
|
13 |
# Azure configuration
|
14 |
ENDPOINT = "https://acae-afd.documents.azure.com:443/"
|
15 |
DATABASE_NAME = os.environ.get("COSMOS_DATABASE_NAME")
|
16 |
CONTAINER_NAME = os.environ.get("COSMOS_CONTAINER_NAME")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# GitHub configuration
|
19 |
def download_github_repo(url, local_path):
|
20 |
if os.path.exists(local_path):
|
@@ -78,28 +108,51 @@ if 'logged_in' not in st.session_state:
|
|
78 |
# Login section
|
79 |
if not st.session_state.logged_in:
|
80 |
st.subheader("π Login")
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
85 |
if st.button("π Login"):
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
else:
|
102 |
-
# Main app content
|
103 |
col1, col2 = st.columns([1, 3])
|
104 |
|
105 |
with col1:
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import pandas as pd
|
4 |
+
from azure.identity import AzureCliCredential, DefaultAzureCredential
|
5 |
from azure.mgmt.resource import ResourceManagementClient
|
6 |
from azure.cosmos import CosmosClient, exceptions
|
7 |
from github import Github
|
|
|
9 |
import shutil
|
10 |
from datetime import datetime
|
11 |
import base64
|
12 |
+
from playwright.sync_api import sync_playwright
|
13 |
+
import time
|
14 |
|
15 |
# Azure configuration
|
16 |
ENDPOINT = "https://acae-afd.documents.azure.com:443/"
|
17 |
DATABASE_NAME = os.environ.get("COSMOS_DATABASE_NAME")
|
18 |
CONTAINER_NAME = os.environ.get("COSMOS_CONTAINER_NAME")
|
19 |
|
20 |
+
# Playwright function for Azure login
|
21 |
+
def azure_login_with_playwright(username, password):
|
22 |
+
with sync_playwright() as p:
|
23 |
+
browser = p.chromium.launch(headless=False) # Set to True for headless mode
|
24 |
+
page = browser.new_page()
|
25 |
+
page.goto("https://portal.azure.com")
|
26 |
+
|
27 |
+
# Wait for and fill in the email field
|
28 |
+
page.wait_for_selector('input[type="email"]')
|
29 |
+
page.fill('input[type="email"]', username)
|
30 |
+
page.click('input[type="submit"]')
|
31 |
+
|
32 |
+
# Wait for and fill in the password field
|
33 |
+
page.wait_for_selector('input[type="password"]')
|
34 |
+
page.fill('input[type="password"]', password)
|
35 |
+
page.click('input[type="submit"]')
|
36 |
+
|
37 |
+
# Wait for login to complete (adjust as needed)
|
38 |
+
page.wait_for_selector('button[id="nav_menu"]', timeout=60000)
|
39 |
+
|
40 |
+
# At this point, the login should be complete
|
41 |
+
# You may want to extract any necessary tokens or cookies here
|
42 |
+
|
43 |
+
browser.close()
|
44 |
+
|
45 |
+
# For now, we'll just return True to indicate successful login
|
46 |
+
return True
|
47 |
+
|
48 |
# GitHub configuration
|
49 |
def download_github_repo(url, local_path):
|
50 |
if os.path.exists(local_path):
|
|
|
108 |
# Login section
|
109 |
if not st.session_state.logged_in:
|
110 |
st.subheader("π Login")
|
111 |
+
st.write("Please enter your Azure Subscription ID. You can find this in the Azure Portal under Subscriptions.")
|
112 |
+
subscription_id = st.text_input("Azure Subscription ID", value="003fba60-5b3f-48f4-ab36-3ed11bc40816")
|
113 |
+
|
114 |
+
login_method = st.radio("Choose login method", ["Automatic", "Manual (Browser Simulation)"])
|
115 |
+
|
116 |
+
if login_method == "Manual (Browser Simulation)":
|
117 |
+
username = st.text_input("Azure Username/Email")
|
118 |
+
password = st.text_input("Azure Password", type="password")
|
119 |
+
|
120 |
if st.button("π Login"):
|
121 |
+
if login_method == "Automatic":
|
122 |
+
try:
|
123 |
+
# First, try AzureCliCredential
|
124 |
+
credential = AzureCliCredential()
|
125 |
+
credential.get_token("https://management.azure.com/.default")
|
126 |
+
except Exception:
|
127 |
+
# If AzureCliCredential fails, fall back to DefaultAzureCredential
|
128 |
+
try:
|
129 |
+
credential = DefaultAzureCredential()
|
130 |
+
credential.get_token("https://management.azure.com/.default")
|
131 |
+
except Exception as e:
|
132 |
+
st.error(f"Failed to authenticate automatically. Please try the Manual (Browser Simulation) method. Error: {str(e)}")
|
133 |
+
st.stop()
|
134 |
+
else:
|
135 |
+
if not username or not password:
|
136 |
+
st.error("Please enter both username and password for manual login.")
|
137 |
+
st.stop()
|
138 |
+
try:
|
139 |
+
if azure_login_with_playwright(username, password):
|
140 |
+
credential = DefaultAzureCredential()
|
141 |
+
credential.get_token("https://management.azure.com/.default")
|
142 |
+
else:
|
143 |
+
st.error("Failed to authenticate using browser simulation.")
|
144 |
+
st.stop()
|
145 |
+
except Exception as e:
|
146 |
+
st.error(f"Failed to authenticate using browser simulation. Error: {str(e)}")
|
147 |
+
st.stop()
|
148 |
+
|
149 |
+
st.session_state.credential = credential
|
150 |
+
st.session_state.subscription_id = subscription_id
|
151 |
+
st.session_state.logged_in = True
|
152 |
+
st.success("Successfully logged in!")
|
153 |
+
st.rerun()
|
154 |
else:
|
155 |
+
# Main app content (unchanged)
|
156 |
col1, col2 = st.columns([1, 3])
|
157 |
|
158 |
with col1:
|