Spaces:
Runtime error
Runtime error
File size: 1,735 Bytes
3065c83 800bc06 c669fd1 3065c83 800bc06 44c8a81 de8ad27 800bc06 44c8a81 c669fd1 44c8a81 800bc06 c669fd1 800bc06 44c8a81 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import streamlit as st
from transformers import pipeline
from PIL import Image
import base64
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
# Set the title and text color to dark green
st.markdown('<h1 style="color:darkgreen;">R3SELL</h1>', unsafe_allow_html=True)
# Create a file input option for uploading an image
file_name = st.file_uploader("Upload an image file (JPEG, PNG, etc.)")
# Create an option to access the camera/webcam
if st.button("Take an image from camera"):
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
if ret:
# Encode the webcam image as a Base64 string
img_encoded = base64.b64encode(cv2.imencode('.jpg', frame)[1]).decode('utf-8')
# Pass the Base64 encoded image to the pipeline function
predictions = pipeline(Image.open('data:image/jpeg;base64,' + img_encoded))
# Replace file_name with the encoded image
file_name = 'webcam_image.jpg'
# Add a text bar to add a title
image_title = st.text_input("Image Title", value="Specificity is nice!")
# Add a text bar to add a description
image_description = st.text_input("Image Description", value="(Optional)")
if file_name is not None:
col1, col2 = st.columns(2)
# Check if the file is a webcam image
if file_name == 'webcam_image.jpg':
# Use the Base64 encoded image
image = Image.open('data:image/jpeg;base64,' + img_encoded)
else:
# Open the uploaded image
image = Image.open(file_name)
col1.image(image, use_column_width=True)
predictions = pipeline(image)
col2.header("Probabilities")
for p in predictions:
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|