|
import streamlit as st |
|
from transformers import AutoProcessor, AutoModelForImageClassification |
|
from PIL import Image |
|
import requests |
|
|
|
|
|
st.title("RADPID: Assistant de diagnostic radiologique") |
|
st.markdown("**Chargez une radiographie et sélectionnez la tâche souhaitée :**") |
|
|
|
|
|
task = st.radio("Sélectionnez une tâche", ["Fracture Detection", "Pneumothorax Detection", "Pneumonia Detection"]) |
|
|
|
|
|
models = { |
|
"Fracture Detection": "facebook/detr-resnet-50", |
|
"Pneumothorax Detection": "RGDancer/Pneumothorax_detection", |
|
"Pneumonia Detection": "wanghaoy/Chest_XRay_Pneumonia", |
|
} |
|
|
|
|
|
model_name = models[task] |
|
processor = AutoProcessor.from_pretrained(model_name) |
|
model = AutoModelForImageClassification.from_pretrained(model_name) |
|
|
|
|
|
uploaded_file = st.file_uploader("Upload your Chest X-Ray image", type=["png", "jpg", "jpeg"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file).convert("RGB") |
|
st.image(image, caption="Image Uploadée", use_column_width=True) |
|
|
|
|
|
st.markdown("### Résultat de la prédiction :") |
|
with st.spinner("Analyse en cours..."): |
|
inputs = processor(images=image, return_tensors="pt") |
|
outputs = model(**inputs) |
|
predictions = outputs.logits.softmax(dim=-1).tolist() |
|
|
|
|
|
st.write(f"Scores pour la tâche '{task}':") |
|
st.json(predictions) |
|
|
|
|