yeftakun commited on
Commit
697c4ae
·
verified ·
1 Parent(s): daa6690

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -27,14 +27,19 @@ def predict_image(image):
27
  # Streamlit app
28
  st.title("NSFW Image Classifier")
29
 
30
- # Upload image file
31
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
32
- if uploaded_file is not None:
33
- image = Image.open(uploaded_file)
34
- st.image(image, caption='Uploaded Image.', use_column_width=True)
35
- st.write("")
36
- st.write("Classifying...")
 
 
 
37
 
38
- # Predict and display result
39
- prediction = predict_image(image)
40
- st.write(f"Predicted Class: {prediction}")
 
 
 
27
  # Streamlit app
28
  st.title("NSFW Image Classifier")
29
 
30
+ # URL input
31
+ image_url = st.text_input("Enter Image URL", placeholder="Enter image URL here")
32
+ if image_url:
33
+ try:
34
+ # Load image from URL
35
+ response = requests.get(image_url)
36
+ image = Image.open(BytesIO(response.content))
37
+ st.image(image, caption='Image from URL', use_column_width=True)
38
+ st.write("")
39
+ st.write("Classifying...")
40
 
41
+ # Predict and display result
42
+ prediction = predict_image(image)
43
+ st.write(f"Predicted Class: {prediction}")
44
+ except Exception as e:
45
+ st.write(f"Error: {e}")