Spaces:
Sleeping
Sleeping
francoisMav
commited on
Commit
•
e069226
1
Parent(s):
0e9e2ef
Updated app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,38 @@
|
|
1 |
-
# app.py
|
2 |
-
|
3 |
-
import streamlit as st
|
4 |
-
from transformers import pipeline
|
5 |
-
from PIL import Image
|
6 |
import requests
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
# Title of the Streamlit app
|
12 |
-
st.title("Skin Condition Classification - Acne Detection")
|
13 |
|
14 |
-
#
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
image =
|
20 |
-
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
+
from io import BytesIO
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
|
6 |
+
def get_acne_classification(image_input):
|
7 |
+
# Hugging Face Spaces URL
|
8 |
+
url = "https://huggingface.co/spaces/francoisMav/skin_acne" # Update with your actual Space URL
|
|
|
|
|
9 |
|
10 |
+
# Check if the input is a URL or a local file
|
11 |
+
if image_input.startswith('http://') or image_input.startswith('https://'):
|
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 |
+
# Convert image to the format needed for Hugging Face Spaces
|
26 |
+
buffered = BytesIO()
|
27 |
+
image.save(buffered, format="JPEG")
|
28 |
+
buffered.seek(0)
|
29 |
|
30 |
+
# Send the image to the Hugging Face Space via POST request
|
31 |
+
files = {'file': buffered}
|
32 |
+
response = requests.post(url, files=files)
|
33 |
|
34 |
+
# Check the response and return the prediction
|
35 |
+
if response.status_code == 200:
|
36 |
+
return response.json() # Adjust based on how your Space returns predictions
|
37 |
+
else:
|
38 |
+
return {"error": "Failed to get prediction from Hugging Face Space"}
|