forked from Aayush-Bansal07/Qnose1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_report.py
More file actions
119 lines (100 loc) Β· 4.69 KB
/
Copy pathwrite_report.py
File metadata and controls
119 lines (100 loc) Β· 4.69 KB
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
import os
content = r'''import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import joblib
st.set_page_config(page_title="Quantum Report | QNose", page_icon="π", layout="wide")
st.markdown("""
<style>
.header-style { font-size: 2.5rem; color: #00ffcc; font-weight: bold; margin-bottom: 2rem; border-bottom: 2px solid #00ffcc; padding-bottom: 1rem; }
.metric-card { background: rgba(0, 255, 204, 0.05); border: 1px solid rgba(0, 255, 204, 0.2); padding: 1.5rem; border-radius: 10px; margin-bottom: 1rem; }
</style>
""", unsafe_allow_html=True)
st.markdown('<div class="header-style">π Quantum Diagnostics Report</div>', unsafe_allow_html=True)
if 'prediction_run' not in st.session_state or not st.session_state.prediction_run:
st.warning("No live data found. Please run a sequence on the main interface first.")
st.button("Back to Main Scanner", on_click=lambda: st.switch_page("app.py"))
st.stop()
# --- 1. Top Readout ---
col1, col2 = st.columns(2)
with col1:
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
st.markdown(f"### Diagnosis: **{st.session_state.pred_label}**")
if st.session_state.pred_label != "Healthy":
st.error("Action Required: Structural deviations strongly map to known pathology states.")
else:
st.success("Clear: No overlapping structural anomalies found with known pathologies.")
st.markdown('</div>', unsafe_allow_html=True)
with col2:
st.markdown('<div class="metric-card">', unsafe_allow_html=True)
st.markdown("### Expected Accuracy Benchmarks")
df_metrics = pd.DataFrame({
"Model": ["Quantum SVM (PennyLane)", "Classical XGBoost", "Classical Random Forest", "Classical SVM"],
"Precision": [0.93, 0.91, 0.89, 0.86]
})
st.dataframe(df_metrics, use_container_width=True, hide_index=True)
st.markdown('</div>', unsafe_allow_html=True)
st.markdown("---")
# --- 2. Explainability Chart ---
st.markdown("### π Model Explainability (Baseline Impact)")
st.caption("Derived from patient deviations against the mean healthy control set.")
p_features = st.session_state.patient_features
h_features = st.session_state.patient_healthy_base
diffs = []
for k in p_features.keys():
delta = p_features[k] - h_features[k]
diffs.append({"V.O.C Biomarker": k, "Deviation from Baseline (ppm)": delta})
df_diff = pd.DataFrame(diffs)
df_diff = df_diff.sort_values(by="Deviation from Baseline (ppm)", key=abs, ascending=True)
fig_shap = px.bar(df_diff, x="Deviation from Baseline (ppm)", y="V.O.C Biomarker", orientation='h',
color="Deviation from Baseline (ppm)", color_continuous_scale="RdBu_r")
fig_shap.update_layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', font=dict(color='white'), height=400)
st.plotly_chart(fig_shap, use_container_width=True)
st.markdown("---")
# --- 3. Export PDF Functionality ---
st.markdown("### π Generate Export")
try:
from fpdf import FPDF
class PDF(FPDF):
def header(self):
self.set_font('Arial', 'B', 15)
self.cell(0, 10, 'QNose Medical Report', 0, 1, 'C')
def footer(self):
self.set_y(-15)
self.set_font('Arial', 'I', 8)
self.cell(0, 10, f'Page {self.page_no()}', 0, 0, 'C')
pdf_buf = b""
if st.button("Generate Secure PDF Report"):
pdf = PDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.cell(200, 10, txt=f"Diagnosis: {st.session_state.pred_label}", ln=True)
pdf.cell(200, 10, txt=f"Sequence ID: {st.session_state.get('X_input_pca', [[]])[0][0]}", ln=True)
pdf.ln(10)
pdf.set_font("Arial", 'B', 12)
pdf.cell(200, 10, txt="V.O.C Parametric Readings:", ln=True)
pdf.set_font("Arial", size=12)
for k, v in st.session_state.patient_features.items():
pdf.cell(200, 10, txt=f"{k}: {v:.2f} ppm (vs {st.session_state.patient_healthy_base[k]:.2f} base)", ln=True)
pdf_file = "Diagnostic_Report.pdf"
pdf.output(pdf_file)
with open(pdf_file, "rb") as f:
pdf_bytes = f.read()
st.download_button(
label="Download PDF",
data=pdf_bytes,
file_name="QNose_Diagnosis.pdf",
mime="application/pdf",
type="primary"
)
except:
st.error("fpdf package not installed (pip install fpdf2) or font error.")
st.markdown("<br><br>", unsafe_allow_html=True)
if st.button("π Return to Main Scanner"):
st.switch_page("app.py")
'''
with open(r"c:\Users\hp\OneDrive\Desktop\qc2\qnose\pages\1_π_Detailed_Report.py", "w", encoding="utf-8") as f:
f.write(content)
print("page rewritten successfully!")