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