AI-Enthusiast11 commited on
Commit
99ab752
·
verified ·
1 Parent(s): 8a7da25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -10
app.py CHANGED
@@ -2,22 +2,49 @@ import streamlit as st
2
  from image_classifier import classify_image # Import from image_classification.py
3
 
4
  # Title and description for your app
5
- st.title("Image Classifier")
6
- st.write("This app classifies uploaded images using a pre-trained TensorFlow model.")
7
 
8
  # Allow users to upload an image
9
  uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
10
 
11
  if uploaded_image is not None:
12
- # Convert uploaded image to a format suitable for classification
13
- image = cv2.imdecode(np.frombuffer(uploaded_image.read(), np.uint8), cv2.IMREAD_COLOR) # Assuming OpenCV is used for conversion
14
-
15
- # Perform classification using your function
16
- try:
17
  predicted_label, probability = classify_image(image)
18
  st.write("Classified as:")
19
  st.write(f"- {predicted_label}: {probability:.4f}")
20
- except Exception as e: # Catch potential errors during classification
21
- st.error(f"Error during classification: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  else:
23
- st.write("Upload an image to classify it.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from image_classifier import classify_image # Import from image_classification.py
3
 
4
  # Title and description for your app
5
+ st.title("AI vs. Human Art Classifier")
6
+ st.write("This app classifies uploaded images as AI-generated or human-made art.")
7
 
8
  # Allow users to upload an image
9
  uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "jpeg", "png"])
10
 
11
  if uploaded_image is not None:
12
+ # Check if data is available in the uploaded image
13
+ if uploaded_image.read():
14
+ try:
15
+ # Attempt OpenCV decoding (assuming OpenCV is installed)
16
+ image = cv2.imdecode(np.frombuffer(uploaded_image.read(), np.uint8), cv2.IMREAD_COLOR)
17
  predicted_label, probability = classify_image(image)
18
  st.write("Classified as:")
19
  st.write(f"- {predicted_label}: {probability:.4f}")
20
+ except Exception as e:
21
+ # Handle potential OpenCV errors
22
+ st.error(f"Error using OpenCV: {e}")
23
+ # Fallback to Pillow if OpenCV fails
24
+ try:
25
+ from PIL import Image
26
+ image = Image.open(uploaded_image)
27
+ image = image.convert('RGB') # Convert to RGB format
28
+ predicted_label, probability = classify_image(image) # Pass the image to your function
29
+ st.write("Classified as (using Pillow):")
30
+ st.write(f"- {predicted label}: {probability:.4f}")
31
+ except Exception as e:
32
+ st.error(f"Error using Pillow for fallback: {e}")
33
+ else:
34
+ st.error("Please upload a valid image file.")
35
  else:
36
+ st.write("Upload an image to classify it.")
37
+
38
+ # Additional Information (Optional)
39
+
40
+ # Based on the classification results, you might want to:
41
+ # - Display a confidence score (probability) for the classification.
42
+ # - Provide a brief explanation of the factors considered for classification.
43
+ # - Offer resources for learning more about AI-generated art.
44
+
45
+ # Example:
46
+ if predicted_label == "AI-generated art":
47
+ confidence = probability * 100
48
+ st.write(f"Confidence level: {confidence:.2f}%")
49
+ 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.")
50
+ st.write("Learn more about AI-generated art: https://en.wikipedia.org/wiki/Artificial_intelligence_art")