Spaces:
Sleeping
Sleeping
Update ui.py
Browse files
ui.py
CHANGED
|
@@ -29,6 +29,49 @@ def APP():
|
|
| 29 |
|
| 30 |
def sidebarview():
|
| 31 |
'''experimental sidebar'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
with st.sidebar:
|
| 34 |
projects = scan_for_project_availability_cached(st.user.email)
|
|
@@ -100,47 +143,7 @@ def APP():
|
|
| 100 |
unsafe_allow_html=True,
|
| 101 |
)
|
| 102 |
|
| 103 |
-
|
| 104 |
-
@st.cache_data(ttl=20) # Cache for 5 minutes to reduce API calls
|
| 105 |
-
def scan_for_project_availability_cached(user_id):
|
| 106 |
-
try:
|
| 107 |
-
request_url = f"https://thexforce-combat-backend.hf.space/{user_id}/projects"
|
| 108 |
-
response = requests.get(
|
| 109 |
-
request_url,
|
| 110 |
-
headers={
|
| 111 |
-
"Content-Type": "application/json",
|
| 112 |
-
"Authorization": f"Bearer {tok}",
|
| 113 |
-
},
|
| 114 |
-
timeout=10 # Add timeout to prevent hanging
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
if response.status_code == 200:
|
| 118 |
-
response_json = response.json()
|
| 119 |
-
pros = response_json.get("projects", []) # Default to empty list if no projects key
|
| 120 |
-
|
| 121 |
-
project_list = []
|
| 122 |
-
if pros: # Check if pros is not None or empty
|
| 123 |
-
for pro in pros:
|
| 124 |
-
if isinstance(pro, dict):
|
| 125 |
-
project_name = pro.get("project")
|
| 126 |
-
if project_name: # Only add if project name exists
|
| 127 |
-
project_list.append(project_name)
|
| 128 |
-
else:
|
| 129 |
-
if pro: # Only add if pro is not None or empty
|
| 130 |
-
project_list.append(str(pro))
|
| 131 |
-
|
| 132 |
-
return project_list
|
| 133 |
-
else:
|
| 134 |
-
st.error(f"Failed to fetch projects. Status code: {response.status_code}")
|
| 135 |
-
return []
|
| 136 |
-
|
| 137 |
-
except requests.exceptions.RequestException as e:
|
| 138 |
-
st.error(f"Error fetching projects: {str(e)}")
|
| 139 |
-
return []
|
| 140 |
-
except Exception as e:
|
| 141 |
-
st.error(f"Unexpected error: {str(e)}")
|
| 142 |
-
return []
|
| 143 |
-
|
| 144 |
|
| 145 |
|
| 146 |
|
|
|
|
| 29 |
|
| 30 |
def sidebarview():
|
| 31 |
'''experimental sidebar'''
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# Get projects with error handling and caching
|
| 35 |
+
@st.cache_data(ttl=20) # Cache for 5 minutes to reduce API calls
|
| 36 |
+
def scan_for_project_availability_cached(user_id):
|
| 37 |
+
try:
|
| 38 |
+
request_url = f"https://thexforce-combat-backend.hf.space/{user_id}/projects"
|
| 39 |
+
response = requests.get(
|
| 40 |
+
request_url,
|
| 41 |
+
headers={
|
| 42 |
+
"Content-Type": "application/json",
|
| 43 |
+
"Authorization": f"Bearer {tok}",
|
| 44 |
+
},
|
| 45 |
+
timeout=10 # Add timeout to prevent hanging
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if response.status_code == 200:
|
| 49 |
+
response_json = response.json()
|
| 50 |
+
pros = response_json.get("projects", []) # Default to empty list if no projects key
|
| 51 |
+
|
| 52 |
+
project_list = []
|
| 53 |
+
if pros: # Check if pros is not None or empty
|
| 54 |
+
for pro in pros:
|
| 55 |
+
if isinstance(pro, dict):
|
| 56 |
+
project_name = pro.get("project")
|
| 57 |
+
if project_name: # Only add if project name exists
|
| 58 |
+
project_list.append(project_name)
|
| 59 |
+
else:
|
| 60 |
+
if pro: # Only add if pro is not None or empty
|
| 61 |
+
project_list.append(str(pro))
|
| 62 |
+
|
| 63 |
+
return project_list
|
| 64 |
+
else:
|
| 65 |
+
st.error(f"Failed to fetch projects. Status code: {response.status_code}")
|
| 66 |
+
return []
|
| 67 |
+
|
| 68 |
+
except requests.exceptions.RequestException as e:
|
| 69 |
+
st.error(f"Error fetching projects: {str(e)}")
|
| 70 |
+
return []
|
| 71 |
+
except Exception as e:
|
| 72 |
+
st.error(f"Unexpected error: {str(e)}")
|
| 73 |
+
return []
|
| 74 |
+
|
| 75 |
|
| 76 |
with st.sidebar:
|
| 77 |
projects = scan_for_project_availability_cached(st.user.email)
|
|
|
|
| 143 |
unsafe_allow_html=True,
|
| 144 |
)
|
| 145 |
|
| 146 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
|
| 149 |
|