Spaces:
Sleeping
Sleeping
francoisMav
commited on
Commit
•
643ce24
1
Parent(s):
e069226
Updated app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,28 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
3 |
from PIL import Image
|
4 |
-
import
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
url = "https://huggingface.co/spaces/francoisMav/skin_acne" # Update with your actual Space URL
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
# If it's a URL, download the image
|
13 |
-
response = requests.get(image_input)
|
14 |
-
if response.status_code == 200:
|
15 |
-
# Load the image into memory using PIL
|
16 |
-
image = Image.open(BytesIO(response.content))
|
17 |
-
else:
|
18 |
-
return {"error": "Failed to download image from URL"}
|
19 |
-
elif os.path.isfile(image_input):
|
20 |
-
# If it's a file path, open the image
|
21 |
-
image = Image.open(image_input)
|
22 |
-
else:
|
23 |
-
return {"error": "Invalid image input. Must be a URL or valid file path."}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
image.
|
28 |
-
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
else:
|
38 |
-
return {"error": "Failed to get prediction from Hugging Face Space"}
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
from transformers import pipeline
|
5 |
from PIL import Image
|
6 |
+
import requests
|
7 |
+
|
8 |
+
# Load the Hugging Face pipeline for image classification
|
9 |
+
classifier = pipeline("image-classification", model="imfarzanansari/skintelligent-acne")
|
10 |
|
11 |
+
# Title of the Streamlit app
|
12 |
+
st.title("Skin Condition Classification - Acne Detection")
|
|
|
13 |
|
14 |
+
# Upload an image file
|
15 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
if uploaded_file is not None:
|
18 |
+
# Display the uploaded image
|
19 |
+
image = Image.open(uploaded_file)
|
20 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
21 |
|
22 |
+
# Perform image classification using the Hugging Face pipeline
|
23 |
+
st.write("Classifying...")
|
24 |
+
predictions = classifier(image)
|
25 |
|
26 |
+
# Display the results
|
27 |
+
for pred in predictions:
|
28 |
+
st.write(f"Label: {pred['label']}, Score: {pred['score']:.4f}")
|
|
|
|