chessfromthefuture commited on
Commit
0966749
·
verified ·
1 Parent(s): 0df54e0

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+ import io
5
+
6
+ # Load the Hugging Face image classification model
7
+ classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
8
+
9
+ # Streamlit UI
10
+ st.title("Image Classifier with Hugging Face 🤗")
11
+ st.write("Upload an image, and the model will predict its content!")
12
+
13
+ # Upload file
14
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
15
+
16
+ if uploaded_file is not None:
17
+ # Display the uploaded image
18
+ image = Image.open(uploaded_file)
19
+ st.image(image, caption="Uploaded Image", use_column_width=True)
20
+
21
+ # Run classification
22
+ st.write("Classifying...")
23
+ results = classifier(image)
24
+
25
+ # Display results
26
+ for result in results:
27
+ st.write(f"**{result['label']}**: {result['score']:.4f}")