DevLujain commited on
Commit
e742708
Β·
1 Parent(s): 9a86486

Add FYP dashboard

Browse files
Files changed (4) hide show
  1. Dockerfile +14 -0
  2. app.py +7 -0
  3. dashboard.py +131 -0
  4. requirements.txt +10 -0
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ RUN useradd -m -u 1000 user
4
+ USER user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
+ WORKDIR /app
8
+
9
+ COPY --chown=user ./requirements.txt requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
11
+
12
+ COPY --chown=user . /app
13
+
14
+ CMD ["streamlit", "run", "dashboard.py", "--server.port=7860", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+
3
+ app = FastAPI()
4
+
5
+ @app.get("/")
6
+ def home():
7
+ return {"status": "FYP Dashboard Running"}
dashboard.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Monitoring", layout="wide")
8
+
9
+ st.title("πŸš€ Multi-Agent Knowledge System - Monitoring Dashboard")
10
+
11
+ # Sidebar for controls
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
+ with col1:
53
+ st.metric("Total Queries", metrics.get("total_queries", 0))
54
+ with col2:
55
+ st.metric("Avg Latency (ms)", f"{metrics.get('avg_latency_ms', 0):.0f}")
56
+ with col3:
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
+ # Query Testing Section
67
+ st.header("πŸ§ͺ Test Queries")
68
+
69
+ query = st.text_input("Enter a query:", "What is FastAPI?")
70
+
71
+ if st.button("Send Query"):
72
+ try:
73
+ with st.spinner("Processing..."):
74
+ response = requests.post(
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(f"βœ… API Status: {health.get('status', 'unknown')}")
128
+ except:
129
+ st.error("❌ API is down")
130
+
131
+ st.info("πŸ’‘ Tip: Keep this dashboard open to monitor your system in real-time!")
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ streamlit
4
+ requests
5
+ plotly
6
+ sentence-transformers
7
+ chromadb
8
+ langchain
9
+ groq
10
+ python-dotenv