Spaces:
Runtime error
Runtime error
Commit ·
032e9d4
1
Parent(s): f6defd1
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839from PIL import Imageimport streamlit as stfrom transformers import CLIPProcessor, CLIPModel
# Load CLIP model and processormodel = CLIPModel.from_pretrained("openai/clip-vit-large-patch14")processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14")
# Function to process the uploaded imagedef process_image(image): # Use the CLIP model to process the image inputs = processor(images=image, return_tensors="pt", padding=True) outputs = model(**inputs) logits_per_image = outputs.logits_per_image probs = logits_per_image.softmax(dim=1) return probs
def main(): st.title("Qadoos Image Classifier") st.subheader("Upload an image") uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
if uploaded_image is not None: # Read the image from uploaded file image = Image.open(uploaded_image)
# Display the uploaded image st.image(image, caption='Uploaded Image.', use_column_width=True)
# Preprocess the image probs = process_image(image)
# Display the result st.subheader("Result") st.json(probs.tolist())
if __name__ == '__main__': main()app.pyAdded+39