abuzarAli's picture
Update app.py
a733905 verified
import streamlit as st
from PIL import Image
from transformers import pipeline
import os
# Check if Groq API key is set and load it if available
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
if GROQ_API_KEY:
from groq import Groq
client = Groq(api_key=GROQ_API_KEY)
# Use Groq API here if you want it for predictions or related tasks
# Streamlit setup
st.title("Pneumonia Chest X-ray Image Detection")
# Upload image
uploaded_image = st.file_uploader("Choose a chest X-ray image...", type=["jpg", "jpeg", "png"])
if uploaded_image is not None:
# Display the image
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded X-ray Image", use_column_width=True)
# Load the Hugging Face model using the pipeline
pipe = pipeline("image-classification", model="dima806/pneumonia_chest_xray_image_detection")
# Run prediction
with st.spinner("Classifying..."):
prediction = pipe(image)
# Display results
st.write(f"Prediction: {prediction[0]['label']}")
st.write(f"Confidence: {prediction[0]['score']:.4f}")
else:
st.warning("Please upload a chest X-ray image to begin detection.")