|
import gradio as gr
|
|
|
|
|
|
from models.image_analyzer import ImageAnalyzer
|
|
from models.multimodal_fusion import MultimodalFusion
|
|
from models.text_analyzer import TextAnalyzer
|
|
from utils.visualization import create_combined_visualization
|
|
|
|
|
|
def process_input(image, medical_report):
|
|
"""Process the image and text inputs and provide combined analysis"""
|
|
|
|
image_analyzer = ImageAnalyzer()
|
|
text_analyzer = TextAnalyzer()
|
|
fusion_model = MultimodalFusion()
|
|
|
|
|
|
image_results = image_analyzer.analyze(image)
|
|
text_results = text_analyzer.analyze(medical_report)
|
|
|
|
|
|
combined_results = fusion_model.fuse_insights(image_results, text_results)
|
|
|
|
|
|
visualization = create_combined_visualization(
|
|
image, image_results, text_results, combined_results
|
|
)
|
|
|
|
|
|
image_findings = "\n".join(
|
|
[
|
|
f"{k}: {v:.2f}" if isinstance(v, float) else f"{k}: {v}"
|
|
for k, v in image_results.items()
|
|
]
|
|
)
|
|
text_findings = "\n".join(
|
|
[f"{k}: {v}" for k, v in text_results.items() if k != "Entities"]
|
|
)
|
|
entities = ", ".join(text_results.get("Entities", []))
|
|
|
|
recommendation = combined_results.get("Recommendation", "No recommendation")
|
|
confidence = combined_results.get("Confidence", "N/A")
|
|
|
|
return (
|
|
visualization,
|
|
image_findings,
|
|
text_findings,
|
|
entities,
|
|
recommendation,
|
|
confidence,
|
|
)
|
|
|
|
|
|
|
|
with gr.Blocks(title="MediSync: Multi-Modal Medical Analysis System") as demo:
|
|
gr.Markdown("# MediSync: Multi-Modal Medical Analysis System")
|
|
gr.Markdown(
|
|
"Upload a chest X-ray image and provide a medical report for comprehensive analysis"
|
|
)
|
|
|
|
with gr.Row():
|
|
with gr.Column():
|
|
image_input = gr.Image(type="pil", label="Upload X-ray Image")
|
|
text_input = gr.Textbox(lines=10, label="Enter Medical Report")
|
|
submit_btn = gr.Button("Analyze")
|
|
|
|
with gr.Column():
|
|
output_image = gr.Image(type="pil", label="Visualization")
|
|
|
|
with gr.Tab("Summary"):
|
|
recommendation_output = gr.Textbox(label="Recommendation")
|
|
confidence_output = gr.Textbox(label="Confidence Score")
|
|
|
|
with gr.Tab("Detailed Results"):
|
|
image_output = gr.Textbox(label="Image Analysis")
|
|
text_output = gr.Textbox(label="Text Analysis")
|
|
entities_output = gr.Textbox(label="Detected Medical Entities")
|
|
|
|
submit_btn.click(
|
|
process_input,
|
|
inputs=[image_input, text_input],
|
|
outputs=[
|
|
output_image,
|
|
image_output,
|
|
text_output,
|
|
entities_output,
|
|
recommendation_output,
|
|
confidence_output,
|
|
],
|
|
)
|
|
|
|
gr.Markdown("""
|
|
## About MediSync
|
|
|
|
MediSync is an AI-powered healthcare solution that combines X-ray image analysis with patient report text processing
|
|
to provide comprehensive medical insights.
|
|
|
|
**Note:** This system is designed as a support tool and should not replace professional medical diagnosis.
|
|
Always consult with healthcare professionals for medical decisions.
|
|
""")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|
|
|