Spaces:
Runtime error
Runtime error
import streamlit as st | |
from image_classifier import classify_image # Import from image_classification.py | |
# Title and description for your app | |
st.title("AI vs. Human Art Classifier") | |
st.write("This app classifies uploaded images as AI-generated or human-made art.") | |
# Allow users to upload an image | |
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"]) | |
if uploaded_image is not None: | |
# Check if data is available in the uploaded image | |
if uploaded_image.read(): | |
try: | |
# Attempt OpenCV decoding (assuming OpenCV is installed) | |
image = cv2.imdecode(np.frombuffer(uploaded_image.read(), np.uint8), cv2.IMREAD_COLOR) | |
predicted_label, probability = classify_image(image) | |
st.write("Classified as:") | |
st.write(f"- {predicted_label}: {probability:.4f}") | |
except Exception as e: | |
# Handle potential OpenCV errors | |
st.error(f"Error using OpenCV: {e}") | |
# Fallback to Pillow if OpenCV fails | |
try: | |
from PIL import Image | |
image = Image.open(uploaded_image) | |
image = image.convert('RGB') # Convert to RGB format | |
predicted_label, probability = classify_image(image) # Pass the image to your function | |
st.write("Classified as (using Pillow):") | |
st.write(f"- {predicted_label}, {probability:.4f}") | |
except Exception as e: | |
st.error(f"Error using Pillow for fallback: {e}") | |
else: | |
st.error("Please upload a valid image file.") | |
else: | |
st.write("Upload an image to classify it.") | |
# Additional Information (Optional) | |
# Based on the classification results, you might want to: | |
# - Display a confidence score (probability) for the classification. | |
# - Provide a brief explanation of the factors considered for classification. | |
# - Offer resources for learning more about AI-generated art. | |
# Example: | |
if predicted_label == "AI-generated art": | |
confidence = probability * 100 | |
st.write(f"Confidence level: {confidence:.2f}%") | |
st.write("AI-generated art often exhibits certain stylistic elements or patterns that can be identified by machine learning models. However, human-made art can also incorporate similar elements, and perfect accuracy cannot be guaranteed.") | |
st.write("Learn more about AI-generated art: https://en.wikipedia.org/wiki/Artificial_intelligence_art") |