Spaces:
Sleeping
Sleeping
added camera feature
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ st.markdown(
|
|
35 |
|
36 |
# Streamlit app title and instructions
|
37 |
st.title("VisionDerm")
|
38 |
-
st.write("Upload an image to identify the skin condition.")
|
39 |
|
40 |
# Column layout for input and display
|
41 |
col1, col2 = st.columns([3, 2])
|
@@ -43,20 +43,28 @@ col1, col2 = st.columns([3, 2])
|
|
43 |
with col1:
|
44 |
# File uploader for image
|
45 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
46 |
prompt = 'Identify the skin condition?'
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
with col2:
|
49 |
-
if
|
50 |
-
#
|
51 |
-
input_image = Image.open(uploaded_file).convert("RGB")
|
52 |
resized_image = input_image.resize((300, 300))
|
53 |
-
st.image(resized_image, caption="
|
54 |
|
55 |
# Resize image for processing (512x512 pixels)
|
56 |
max_size = (512, 512)
|
57 |
processed_image = input_image.resize(max_size)
|
58 |
|
59 |
-
# Predict automatically when the image is uploaded or
|
60 |
with st.spinner("Processing..."):
|
61 |
try:
|
62 |
# Prepare inputs
|
@@ -72,21 +80,17 @@ with col2:
|
|
72 |
with torch.no_grad():
|
73 |
outputs = model.generate(**inputs, max_new_tokens=default_max_tokens)
|
74 |
|
75 |
-
# Decode output and remove the prompt text
|
76 |
decoded_output = processor.decode(outputs[0], skip_special_tokens=True)
|
77 |
-
|
78 |
-
# Remove the prompt text from the model output if present
|
79 |
if prompt in decoded_output:
|
80 |
decoded_output = decoded_output.replace(prompt, "").strip()
|
81 |
-
|
82 |
# Capitalize the first letter of each word
|
83 |
decoded_output = decoded_output.title()
|
84 |
-
|
85 |
# Display result
|
86 |
st.success("Analysis Complete!")
|
87 |
st.write("**Model Output:**", decoded_output)
|
88 |
|
89 |
-
|
90 |
-
|
91 |
except Exception as e:
|
92 |
st.error(f"Error: {str(e)}")
|
|
|
35 |
|
36 |
# Streamlit app title and instructions
|
37 |
st.title("VisionDerm")
|
38 |
+
st.write("Upload an image or use your camera to identify the skin condition.")
|
39 |
|
40 |
# Column layout for input and display
|
41 |
col1, col2 = st.columns([3, 2])
|
|
|
43 |
with col1:
|
44 |
# File uploader for image
|
45 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
46 |
+
# Camera input for photo capture
|
47 |
+
camera_photo = st.camera_input("Take a photo")
|
48 |
prompt = 'Identify the skin condition?'
|
49 |
|
50 |
+
# Choose input image (either uploaded or taken by camera)
|
51 |
+
input_image = None
|
52 |
+
if camera_photo:
|
53 |
+
input_image = Image.open(camera_photo)
|
54 |
+
elif uploaded_file:
|
55 |
+
input_image = Image.open(uploaded_file)
|
56 |
+
|
57 |
with col2:
|
58 |
+
if input_image:
|
59 |
+
# Display the image
|
|
|
60 |
resized_image = input_image.resize((300, 300))
|
61 |
+
st.image(resized_image, caption="Selected Image (300x300)", use_container_width=True)
|
62 |
|
63 |
# Resize image for processing (512x512 pixels)
|
64 |
max_size = (512, 512)
|
65 |
processed_image = input_image.resize(max_size)
|
66 |
|
67 |
+
# Predict automatically when the image is uploaded or captured
|
68 |
with st.spinner("Processing..."):
|
69 |
try:
|
70 |
# Prepare inputs
|
|
|
80 |
with torch.no_grad():
|
81 |
outputs = model.generate(**inputs, max_new_tokens=default_max_tokens)
|
82 |
|
83 |
+
# Decode output and remove the prompt text
|
84 |
decoded_output = processor.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
85 |
if prompt in decoded_output:
|
86 |
decoded_output = decoded_output.replace(prompt, "").strip()
|
87 |
+
|
88 |
# Capitalize the first letter of each word
|
89 |
decoded_output = decoded_output.title()
|
90 |
+
|
91 |
# Display result
|
92 |
st.success("Analysis Complete!")
|
93 |
st.write("**Model Output:**", decoded_output)
|
94 |
|
|
|
|
|
95 |
except Exception as e:
|
96 |
st.error(f"Error: {str(e)}")
|