Spaces:
Sleeping
Sleeping
File size: 1,250 Bytes
770451b c3c8396 363e473 fd2ed4d c3c8396 fd2ed4d 38279f0 363e473 fd2ed4d 363e473 fd2ed4d e0ca0de fd2ed4d |
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 |
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) |