File size: 3,494 Bytes
2655fdb |
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 |
import gradio as gr
# Import modules
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"""
# Initialize analyzers
image_analyzer = ImageAnalyzer()
text_analyzer = TextAnalyzer()
fusion_model = MultimodalFusion()
# Analyze inputs
image_results = image_analyzer.analyze(image)
text_results = text_analyzer.analyze(medical_report)
# Fuse insights
combined_results = fusion_model.fuse_insights(image_results, text_results)
# Visualize results
visualization = create_combined_visualization(
image, image_results, text_results, combined_results
)
# Format results for display
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,
)
# Create Gradio interface
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.
""")
# Launch the app
if __name__ == "__main__":
demo.launch()
|