Btdetection / app.py
fahadMizan's picture
Create app.py
77b2cb2 verified
import streamlit as st
from transformers import AutoModelForImageClassification, AutoFeatureExtractor
from PIL import Image
import torch
# Load model and feature extractor
model_name = "fahadMizan/Btdetection" # Replace with your Hugging Face model name
extractor = AutoFeatureExtractor.from_pretrained(model_name)
model = AutoModelForImageClassification.from_pretrained(model_name)
# Streamlit app title
st.title("Brain Tumor Detection")
# Upload image
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
# Open the image
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
# Preprocess the image
inputs = extractor(images=image, return_tensors="pt")
# Make prediction
with torch.no_grad():
outputs = model(**inputs)
# Get predicted class
logits = outputs.logits
predicted_class = logits.argmax(-1).item()
# Display the result
if predicted_class == 0:
st.success("No tumor detected.")
else:
st.error("Tumor detected!")