Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Initialize the model at startup | |
analyzer = pipeline( | |
"image-to-text", | |
model="Salesforce/blip-image-captioning-base" | |
) | |
def analyze_medical_image(image, question=""): | |
"""Analyze medical images with optional question""" | |
try: | |
if image is None: | |
return "β οΈ Please upload a medical image" | |
prompt = ( | |
f"Question: As a radiologist, {question if question else 'describe any abnormalities in this medical scan'}. " | |
"Answer professionally:" | |
) | |
results = analyzer(image, prompt=prompt) | |
return results[0]["generated_text"].replace(prompt, "").strip() | |
except Exception as e: | |
return f"β Error: {str(e)}" | |
# Simple Gradio interface | |
demo = gr.Interface( | |
fn=analyze_medical_image, | |
inputs=[ | |
gr.Image(type="pil", label="Upload Medical Scan"), | |
gr.Textbox(label="Clinical Question (optional)", placeholder="Describe symptoms...") | |
], | |
outputs=gr.Textbox(label="Analysis Report"), | |
title="π©Ί Medical Image Analyzer", | |
description="Upload medical scans (X-rays, CT, MRI) for AI analysis", | |
allow_flagging="never" | |
) | |
demo.launch(show_error=True) |