Code-Nik10/Hospital-Analysis
1
1import gradio as gr2from analysis import end_to_end3 4def analyze_csv(file):5 if file is None:6 return None, None, "Please upload a CSV file or use the sample dataset."7 try:8 counts_df, chart_img, stats_text = end_to_end(file)9 counts_html = counts_df.to_html(index=False)10 return counts_html, chart_img, stats_text11 except Exception as e:12 return None, None, f"Error: {str(e)}"13 14def analyze_sample():15 # Always available sample dataset16 with open("sample_data.csv", "r") as f:17 counts_df, chart_img, stats_text = end_to_end(f)18 counts_html = counts_df.to_html(index=False)19 return counts_html, chart_img, stats_text20 21with gr.Blocks(title="Hospital Department Load Analysis") as demo:22 gr.Markdown("# 🏥 Hospital Department Load Analysis")23 gr.Markdown("Upload a CSV or click **Use Sample Data** to try the app instantly.")24 25 with gr.Row():26 file_input = gr.File(label="Upload CSV", file_types=[".csv"])27 sample_btn = gr.Button("Use Sample Data")28 29 with gr.Row():30 table_out = gr.HTML(label="Counts table")31 image_out = gr.Image(label="Bar chart", type="pil")32 stats_out = gr.Textbox(label="Stats report", lines=8)33 34 analyze_btn = gr.Button("Analyze Uploaded File")35 analyze_btn.click(analyze_csv, inputs=[file_input], outputs=[table_out, image_out, stats_out])36 sample_btn.click(analyze_sample, outputs=[table_out, image_out, stats_out])37 38if __name__ == "__main__":39 demo.launch(server_name="0.0.0.0", server_port=7860)