Spaces:
Sleeping
Sleeping
File size: 3,848 Bytes
068aa4e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
import streamlit as st
import requests
import json
from datetime import datetime
st.set_page_config(page_title="FYP Monitoring", layout="wide")
st.title("π Multi-Agent Knowledge System - Monitoring Dashboard")
st.sidebar.header("βοΈ Controls")
api_url = st.sidebar.text_input("API URL", "http://localhost:8000")
# ====== METRICS SECTION ======
st.header("π System Metrics")
col1, col2, col3, col4 = st.columns(4)
try:
health = requests.get(f"{api_url}/health").json()
with col1:
st.metric("API Status", health.get("status", "unknown"))
except Exception as e:
with col1:
st.error("API Down")
with col2:
st.metric("Region", "Singapore")
with col3:
st.metric("Runtime", "Docker")
with col4:
st.metric("Model", "Mixtral 8x7B")
st.divider()
# ====== TEST QUERIES SECTION ======
st.header("π§ͺ Test Queries")
query = st.text_input("Enter a query:", "What is FastAPI?", key="query_input")
if st.button("Send Query", key="send_button_unique"):
try:
with st.spinner("β³ Processing your query..."):
response = requests.post(
f"{api_url}/query",
json={"query": query},
timeout=30
).json()
st.session_state.last_response = response
st.success("β
Query processed!")
except requests.exceptions.ConnectionError:
st.error("β Cannot connect to API. Check the URL above.")
except requests.exceptions.Timeout:
st.error("β Request timed out. API is taking too long.")
except json.JSONDecodeError:
st.error("β API returned invalid JSON. Check if API is running.")
except Exception as e:
st.error(f"β Error: {str(e)}")
# Display response if it exists
if 'last_response' in st.session_state:
response = st.session_state.last_response
# Display Answer
st.subheader("π Answer")
st.write(response.get("answer", "No answer available"))
# Display Confidence & Time
col1, col2, col3 = st.columns(3)
with col1:
confidence = response.get("validation", {}).get("confidence", 0)
st.metric("Confidence", f"{confidence}%")
with col2:
status = response.get("validation", {}).get("status", "Unknown")
st.metric("Status", status)
with col3:
st.metric("Sources Found", len(response.get("sources", [])))
# Display Sources
if response.get("sources"):
st.subheader("π Retrieved Sources")
for i, source in enumerate(response.get("sources", []), 1):
st.write(f"**{i}. {source['source']}** - Relevance: {source['relevance']:.0%}")
# Show raw response in expander
with st.expander("π Show Raw Response"):
st.json(response)
# ====== SYSTEM HEALTH ======
st.header("π₯ System Health")
col1, col2 = st.columns(2)
with col1:
try:
health = requests.get(f"{api_url}/health", timeout=5).json()
st.success(f"β
API Status: {health.get('status', 'unknown').upper()}")
st.json(health)
except Exception as e:
st.error(f"β API is down: {str(e)}")
with col2:
st.info("π‘ Tips:\n- Change API URL in sidconfidenceebar\n- Check Render logs if API fails\n- Use http://localhost:8000 for local testing")
st.divider()
# ====== QUERY HISTORY ======
st.header("π Query History")
if 'query_history' not in st.session_state:
st.session_state.query_history = []
# Clear history button
if st.button("Clear History", key="clear_history_button"):
st.session_state.query_history = []
st.success("β
History cleared!")
# Display history
if st.session_state.query_history:
for i, item in enumerate(reversed(st.session_state.query_history[-10:]), 1):
st.write(f"{i}. **{item['query']}** - {item['time']}")
else:
st.write("No queries yet")
|