Delete app.py
Browse files
app.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
# Import modules
|
| 4 |
-
from models.image_analyzer import ImageAnalyzer
|
| 5 |
-
from models.multimodal_fusion import MultimodalFusion
|
| 6 |
-
from models.text_analyzer import TextAnalyzer
|
| 7 |
-
from utils.visualization import create_combined_visualization
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def process_input(image, medical_report):
|
| 11 |
-
"""Process the image and text inputs and provide combined analysis"""
|
| 12 |
-
# Initialize analyzers
|
| 13 |
-
image_analyzer = ImageAnalyzer()
|
| 14 |
-
text_analyzer = TextAnalyzer()
|
| 15 |
-
fusion_model = MultimodalFusion()
|
| 16 |
-
|
| 17 |
-
# Analyze inputs
|
| 18 |
-
image_results = image_analyzer.analyze(image)
|
| 19 |
-
text_results = text_analyzer.analyze(medical_report)
|
| 20 |
-
|
| 21 |
-
# Fuse insights
|
| 22 |
-
combined_results = fusion_model.fuse_insights(image_results, text_results)
|
| 23 |
-
|
| 24 |
-
# Visualize results
|
| 25 |
-
visualization = create_combined_visualization(
|
| 26 |
-
image, image_results, text_results, combined_results
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
# Format results for display
|
| 30 |
-
image_findings = "\n".join(
|
| 31 |
-
[
|
| 32 |
-
f"{k}: {v:.2f}" if isinstance(v, float) else f"{k}: {v}"
|
| 33 |
-
for k, v in image_results.items()
|
| 34 |
-
]
|
| 35 |
-
)
|
| 36 |
-
text_findings = "\n".join(
|
| 37 |
-
[f"{k}: {v}" for k, v in text_results.items() if k != "Entities"]
|
| 38 |
-
)
|
| 39 |
-
entities = ", ".join(text_results.get("Entities", []))
|
| 40 |
-
|
| 41 |
-
recommendation = combined_results.get("Recommendation", "No recommendation")
|
| 42 |
-
confidence = combined_results.get("Confidence", "N/A")
|
| 43 |
-
|
| 44 |
-
return (
|
| 45 |
-
visualization,
|
| 46 |
-
image_findings,
|
| 47 |
-
text_findings,
|
| 48 |
-
entities,
|
| 49 |
-
recommendation,
|
| 50 |
-
confidence,
|
| 51 |
-
)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# Create Gradio interface
|
| 55 |
-
with gr.Blocks(title="MediSync: Multi-Modal Medical Analysis System") as demo:
|
| 56 |
-
gr.Markdown("# MediSync: Multi-Modal Medical Analysis System")
|
| 57 |
-
gr.Markdown(
|
| 58 |
-
"Upload a chest X-ray image and provide a medical report for comprehensive analysis"
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
with gr.Row():
|
| 62 |
-
with gr.Column():
|
| 63 |
-
image_input = gr.Image(type="pil", label="Upload X-ray Image")
|
| 64 |
-
text_input = gr.Textbox(lines=10, label="Enter Medical Report")
|
| 65 |
-
submit_btn = gr.Button("Analyze")
|
| 66 |
-
|
| 67 |
-
with gr.Column():
|
| 68 |
-
output_image = gr.Image(type="pil", label="Visualization")
|
| 69 |
-
|
| 70 |
-
with gr.Tab("Summary"):
|
| 71 |
-
recommendation_output = gr.Textbox(label="Recommendation")
|
| 72 |
-
confidence_output = gr.Textbox(label="Confidence Score")
|
| 73 |
-
|
| 74 |
-
with gr.Tab("Detailed Results"):
|
| 75 |
-
image_output = gr.Textbox(label="Image Analysis")
|
| 76 |
-
text_output = gr.Textbox(label="Text Analysis")
|
| 77 |
-
entities_output = gr.Textbox(label="Detected Medical Entities")
|
| 78 |
-
|
| 79 |
-
submit_btn.click(
|
| 80 |
-
process_input,
|
| 81 |
-
inputs=[image_input, text_input],
|
| 82 |
-
outputs=[
|
| 83 |
-
output_image,
|
| 84 |
-
image_output,
|
| 85 |
-
text_output,
|
| 86 |
-
entities_output,
|
| 87 |
-
recommendation_output,
|
| 88 |
-
confidence_output,
|
| 89 |
-
],
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
gr.Markdown("""
|
| 93 |
-
## About MediSync
|
| 94 |
-
|
| 95 |
-
MediSync is an AI-powered healthcare solution that combines X-ray image analysis with patient report text processing
|
| 96 |
-
to provide comprehensive medical insights.
|
| 97 |
-
|
| 98 |
-
**Note:** This system is designed as a support tool and should not replace professional medical diagnosis.
|
| 99 |
-
Always consult with healthcare professionals for medical decisions.
|
| 100 |
-
""")
|
| 101 |
-
|
| 102 |
-
# Launch the app
|
| 103 |
-
if __name__ == "__main__":
|
| 104 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|