Create AdminDashboard.py
Browse files- AdminDashboard.py +65 -0
AdminDashboard.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import boto3
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
# AWS DynamoDB config
|
| 7 |
+
dynamodb = boto3.client(
|
| 8 |
+
"dynamodb",
|
| 9 |
+
region_name=os.getenv("DYNAMODB_REGION", "ap-south-1"),
|
| 10 |
+
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
|
| 11 |
+
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
TABLE_NAME = os.getenv("SESSION_TABLE", "SessionTracking")
|
| 15 |
+
|
| 16 |
+
# Page Config
|
| 17 |
+
st.set_page_config(
|
| 18 |
+
page_title="π Admin Dashboard - Base Videos",
|
| 19 |
+
layout="wide",
|
| 20 |
+
initial_sidebar_state="expanded",
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
st.markdown("<h1 style='color:#4F97FF;text-align:center;'>π Base Video Generation Dashboard</h1>", unsafe_allow_html=True)
|
| 24 |
+
|
| 25 |
+
# Fetch all sessions
|
| 26 |
+
def fetch_sessions():
|
| 27 |
+
try:
|
| 28 |
+
response = dynamodb.scan(TableName=TABLE_NAME)
|
| 29 |
+
items = response.get("Items", [])
|
| 30 |
+
sessions = []
|
| 31 |
+
for item in items:
|
| 32 |
+
sessions.append({
|
| 33 |
+
"session_id": item.get("session_id", {}).get("S"),
|
| 34 |
+
"status": item.get("status", {}).get("S", "unknown"),
|
| 35 |
+
"node": item.get("node", {}).get("S", "-"),
|
| 36 |
+
"updated_at": item.get("updated_at", {}).get("S", "-"),
|
| 37 |
+
"video_url": item.get("video_url", {}).get("S", None), # optional if final node adds it
|
| 38 |
+
})
|
| 39 |
+
return sessions
|
| 40 |
+
except Exception as e:
|
| 41 |
+
st.error(f"β οΈ Error fetching sessions: {e}")
|
| 42 |
+
return []
|
| 43 |
+
|
| 44 |
+
# Auto-refresh every 15 seconds
|
| 45 |
+
st_autorefresh = st.empty()
|
| 46 |
+
sessions = fetch_sessions()
|
| 47 |
+
|
| 48 |
+
if not sessions:
|
| 49 |
+
st.warning("No sessions found yet.")
|
| 50 |
+
else:
|
| 51 |
+
for s in sessions:
|
| 52 |
+
with st.container():
|
| 53 |
+
st.markdown(f"""
|
| 54 |
+
<div style="background:#2D2D2D;padding:1rem;border-radius:10px;margin-bottom:1rem;border:1px solid #444;">
|
| 55 |
+
<b>π Session:</b> <code>{s['session_id']}</code><br>
|
| 56 |
+
<b>π Current Node:</b> {s['node']}<br>
|
| 57 |
+
<b>π Status:</b> <span style="color:{'lime' if s['status']=='completed' else 'orange'};">{s['status']}</span><br>
|
| 58 |
+
<b>β±οΈ Last Update:</b> {s['updated_at']}<br>
|
| 59 |
+
{"<b>π₯ Final Video:</b> <a href='"+s['video_url']+"' target='_blank'>Watch here</a>" if s['video_url'] else ""}
|
| 60 |
+
</div>
|
| 61 |
+
""", unsafe_allow_html=True)
|
| 62 |
+
|
| 63 |
+
# Manual refresh button
|
| 64 |
+
if st.button("π Refresh Now"):
|
| 65 |
+
st.rerun()
|