Spaces:
Sleeping
Sleeping
DevLujain commited on
Commit Β·
531223c
1
Parent(s): e742708
Replace dashboard with clean version
Browse files- dashboard.py +19 -112
dashboard.py
CHANGED
|
@@ -1,131 +1,38 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
-
import json
|
| 4 |
from datetime import datetime
|
| 5 |
-
import time
|
| 6 |
|
| 7 |
-
st.set_page_config(page_title="FYP
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
st.sidebar.header("βοΈ Controls")
|
| 13 |
-
if st.sidebar.checkbox("π Show Performance Charts"):
|
| 14 |
-
col1, col2 = st.columns(2)
|
| 15 |
-
|
| 16 |
-
with col1:
|
| 17 |
-
# Latency chart
|
| 18 |
-
fig = go.Figure()
|
| 19 |
-
fig.add_trace(go.Indicator(
|
| 20 |
-
mode="gauge+number",
|
| 21 |
-
value=metrics.get('avg_latency_ms', 0),
|
| 22 |
-
title={'text': "Avg Latency (ms)"},
|
| 23 |
-
domain={'x': [0, 1], 'y': [0, 1]},
|
| 24 |
-
gauge={'axis': {'range': [0, 5000]},
|
| 25 |
-
'bar': {'color': "darkblue"},
|
| 26 |
-
'steps': [{'range': [0, 1000], 'color': "lightgray"}]}
|
| 27 |
-
))
|
| 28 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 29 |
-
|
| 30 |
-
with col2:
|
| 31 |
-
# Confidence chart
|
| 32 |
-
fig = go.Figure()
|
| 33 |
-
fig.add_trace(go.Indicator(
|
| 34 |
-
mode="gauge+number",
|
| 35 |
-
value=metrics.get('avg_confidence', 0) * 100,
|
| 36 |
-
title={'text': "Avg Confidence (%)"},
|
| 37 |
-
domain={'x': [0, 1], 'y': [0, 1]},
|
| 38 |
-
gauge={'axis': {'range': [0, 100]},
|
| 39 |
-
'bar': {'color': "darkgreen"},
|
| 40 |
-
'steps': [{'range': [0, 70], 'color': "lightcoral"},
|
| 41 |
-
{'range': [70, 100], 'color': "lightgreen"}]}
|
| 42 |
-
))
|
| 43 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 44 |
-
|
| 45 |
-
# Metrics columns
|
| 46 |
col1, col2, col3, col4 = st.columns(4)
|
| 47 |
|
| 48 |
try:
|
| 49 |
-
# Get metrics from API
|
| 50 |
metrics = requests.get(f"{api_url}/metrics").json()
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
st.metric("Avg Confidence", f"{metrics.get('avg_confidence', 0):.0%}")
|
| 58 |
-
with col4:
|
| 59 |
-
st.metric("Cache Hit Rate", f"{metrics.get('cache_hit_rate', 0):.0%}")
|
| 60 |
-
|
| 61 |
-
except Exception as e:
|
| 62 |
-
st.error(f"β Cannot connect to API: {e}")
|
| 63 |
|
| 64 |
st.divider()
|
| 65 |
|
| 66 |
-
|
| 67 |
-
st.
|
| 68 |
-
|
| 69 |
-
query = st.text_input("Enter a query:", "What is FastAPI?")
|
| 70 |
|
| 71 |
-
if st.button("Send
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
f"{api_url}/query",
|
| 76 |
-
json={"query": query}
|
| 77 |
-
).json()
|
| 78 |
-
|
| 79 |
-
# Display results
|
| 80 |
-
st.success("β
Query processed successfully!")
|
| 81 |
-
|
| 82 |
-
col1, col2 = st.columns([2, 1])
|
| 83 |
-
|
| 84 |
-
with col1:
|
| 85 |
-
st.subheader("π Answer")
|
| 86 |
-
st.write(response.get("answer", "No answer"))
|
| 87 |
-
|
| 88 |
-
with col2:
|
| 89 |
-
st.subheader("π Metrics")
|
| 90 |
-
st.metric("Confidence", f"{response['validation']['confidence']}%")
|
| 91 |
-
st.metric("Processing Time", f"{response['processing_time']:.2f}s")
|
| 92 |
-
st.metric("Status", response['validation']['status'])
|
| 93 |
-
|
| 94 |
-
st.subheader("π Sources")
|
| 95 |
-
for i, source in enumerate(response.get("sources", []), 1):
|
| 96 |
-
st.write(f"{i}. **{source['source']}** (Relevance: {source['relevance']:.0%})")
|
| 97 |
-
|
| 98 |
-
except Exception as e:
|
| 99 |
-
st.error(f"β Error: {e}")
|
| 100 |
|
| 101 |
st.divider()
|
| 102 |
-
|
| 103 |
-
# Query History Section
|
| 104 |
-
|
| 105 |
-
st.header("π Query History")
|
| 106 |
-
|
| 107 |
-
if 'query_history' not in st.session_state:
|
| 108 |
-
st.session_state.query_history = []
|
| 109 |
-
|
| 110 |
-
# Store query in history
|
| 111 |
-
if st.button("Send Query"):
|
| 112 |
-
st.session_state.query_history.append({
|
| 113 |
-
'query': query,
|
| 114 |
-
'time': datetime.now().strftime("%H:%M:%S"),
|
| 115 |
-
'confidence': response['validation']['confidence']
|
| 116 |
-
})
|
| 117 |
-
|
| 118 |
-
# Display history
|
| 119 |
-
for item in reversed(st.session_state.query_history[-5:]):
|
| 120 |
-
st.write(f"π {item['time']} | {item['query']} | Confidence: {item['confidence']}%")
|
| 121 |
-
|
| 122 |
-
# Health Check
|
| 123 |
-
st.header("π₯ System Health")
|
| 124 |
-
|
| 125 |
try:
|
| 126 |
health = requests.get(f"{api_url}/health").json()
|
| 127 |
-
st.success(
|
| 128 |
except:
|
| 129 |
-
st.error("β API
|
| 130 |
-
|
| 131 |
-
st.info("π‘ Tip: Keep this dashboard open to monitor your system in real-time!")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
| 3 |
from datetime import datetime
|
|
|
|
| 4 |
|
| 5 |
+
st.set_page_config(page_title="FYP Dashboard", layout="wide")
|
| 6 |
+
st.title("π Multi-Agent Knowledge System Dashboard")
|
| 7 |
|
| 8 |
+
api_url = "http://localhost:8000"
|
| 9 |
|
| 10 |
+
st.header("π Metrics")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
col1, col2, col3, col4 = st.columns(4)
|
| 12 |
|
| 13 |
try:
|
|
|
|
| 14 |
metrics = requests.get(f"{api_url}/metrics").json()
|
| 15 |
+
col1.metric("Total Queries", metrics.get("total_queries", 0))
|
| 16 |
+
col2.metric("Avg Latency (ms)", f"{metrics.get('avg_latency_ms', 0):.0f}")
|
| 17 |
+
col3.metric("Avg Confidence", f"{metrics.get('avg_confidence', 0):.0%}")
|
| 18 |
+
col4.metric("Cache Hit Rate", f"{metrics.get('cache_hit_rate', 0):.0%}")
|
| 19 |
+
except:
|
| 20 |
+
st.error("Cannot connect to API")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
st.divider()
|
| 23 |
|
| 24 |
+
st.header("π§ͺ Test Query")
|
| 25 |
+
query = st.text_input("Enter query:", "What is FastAPI?")
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
if st.button("Send", key="unique_send"):
|
| 28 |
+
response = requests.post(f"{api_url}/query", json={"query": query}).json()
|
| 29 |
+
st.write(response.get("answer"))
|
| 30 |
+
st.metric("Confidence", f"{response['validation']['confidence']}%")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
st.divider()
|
| 33 |
+
st.header("π₯ Health")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
try:
|
| 35 |
health = requests.get(f"{api_url}/health").json()
|
| 36 |
+
st.success("β
API Running")
|
| 37 |
except:
|
| 38 |
+
st.error("β API Down")
|
|
|
|
|
|