francoisMav commited on
Commit
e069226
1 Parent(s): 0e9e2ef

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -22
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
- # 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}")
 
 
 
 
 
 
 
 
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"}