willco-afk commited on
Commit
a43d43f
·
verified ·
1 Parent(s): f48721f

Create app.py

Browse files

Initial commit with image recognition code

Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from transformers import pipeline
4
+
5
+ # Set up a title for the app
6
+ st.title("Image Recognition App")
7
+
8
+ # Load a pre-trained image classification pipeline from Hugging Face
9
+ classifier = pipeline('image-classification', model='google/efficientnet-b0')
10
+
11
+ # Upload an image
12
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
13
+
14
+ if uploaded_file is not None:
15
+ # Display the uploaded image
16
+ image = Image.open(uploaded_file)
17
+ st.image(image, caption='Uploaded Image.', use_column_width=True)
18
+
19
+ # Run the classifier
20
+ st.write("Classifying...")
21
+ results = classifier(image)
22
+
23
+ # Display the classification results
24
+ st.write("Predictions:")
25
+ for label in results:
26
+ st.write(f"Label: {label['label']}, Confidence: {label['score']:.2f}")