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.title('R3SELL', color='darkgreen') # 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)}%")