Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoProcessor, AutoModelForImageClassification
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
|
6 |
+
# Titre de l'application
|
7 |
+
st.title("RADPID: Assistant de diagnostic radiologique")
|
8 |
+
st.markdown("**Chargez une radiographie et sélectionnez la tâche souhaitée :**")
|
9 |
+
|
10 |
+
# Sélection des tâches
|
11 |
+
task = st.radio("Sélectionnez une tâche", ["Fracture Detection", "Pneumothorax Detection", "Pneumonia Detection"])
|
12 |
+
|
13 |
+
# Modèles
|
14 |
+
models = {
|
15 |
+
"Fracture Detection": "facebook/detr-resnet-50",
|
16 |
+
"Pneumothorax Detection": "RGDancer/Pneumothorax_detection",
|
17 |
+
"Pneumonia Detection": "wanghaoy/Chest_XRay_Pneumonia",
|
18 |
+
}
|
19 |
+
|
20 |
+
# Charger le modèle et le processeur correspondant
|
21 |
+
model_name = models[task]
|
22 |
+
processor = AutoProcessor.from_pretrained(model_name)
|
23 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
24 |
+
|
25 |
+
# Upload de l'image
|
26 |
+
uploaded_file = st.file_uploader("Upload your Chest X-Ray image", type=["png", "jpg", "jpeg"])
|
27 |
+
|
28 |
+
if uploaded_file is not None:
|
29 |
+
# Charger l'image
|
30 |
+
image = Image.open(uploaded_file).convert("RGB")
|
31 |
+
st.image(image, caption="Image Uploadée", use_column_width=True)
|
32 |
+
|
33 |
+
# Effectuer la prédiction
|
34 |
+
st.markdown("### Résultat de la prédiction :")
|
35 |
+
with st.spinner("Analyse en cours..."):
|
36 |
+
inputs = processor(images=image, return_tensors="pt")
|
37 |
+
outputs = model(**inputs)
|
38 |
+
predictions = outputs.logits.softmax(dim=-1).tolist()
|
39 |
+
|
40 |
+
# Afficher les scores
|
41 |
+
st.write(f"Scores pour la tâche '{task}':")
|
42 |
+
st.json(predictions)
|
43 |
+
|