Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,17 +3,15 @@ import torch
|
|
3 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
4 |
from PIL import Image
|
5 |
|
6 |
-
# Load the model and processor
|
7 |
model_id = "brucewayne0459/paligemma_derm"
|
8 |
processor = AutoProcessor.from_pretrained(model_id)
|
9 |
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
|
10 |
model.eval()
|
11 |
|
12 |
-
# Set device
|
13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
14 |
model.to(device)
|
15 |
|
16 |
-
#
|
17 |
st.markdown(
|
18 |
"""
|
19 |
<style>
|
@@ -33,21 +31,19 @@ st.markdown(
|
|
33 |
unsafe_allow_html=True,
|
34 |
)
|
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])
|
42 |
|
43 |
with col1:
|
44 |
-
# File uploader
|
45 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
46 |
-
# Camera input
|
47 |
camera_photo = st.camera_input("Take a photo")
|
48 |
prompt = 'Identify the skin condition?'
|
49 |
|
50 |
-
# Choose input image
|
51 |
input_image = None
|
52 |
if camera_photo:
|
53 |
input_image = Image.open(camera_photo)
|
@@ -56,7 +52,6 @@ elif 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 |
|
@@ -64,10 +59,8 @@ with col2:
|
|
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
|
71 |
inputs = processor(
|
72 |
text=prompt,
|
73 |
images=processed_image,
|
@@ -75,28 +68,23 @@ with col2:
|
|
75 |
padding="longest"
|
76 |
).to(device)
|
77 |
|
78 |
-
# Generate output
|
79 |
default_max_tokens = 50 # Set a default value for max tokens
|
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)}")
|
97 |
|
98 |
-
|
99 |
-
st.markdown("---") # Add a horizontal line for separation
|
100 |
st.info("""
|
101 |
### Team: Mahasigma Berprestasi
|
102 |
- **Muhammad Karov Ardava Barus** ; 103052300001
|
|
|
3 |
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
4 |
from PIL import Image
|
5 |
|
|
|
6 |
model_id = "brucewayne0459/paligemma_derm"
|
7 |
processor = AutoProcessor.from_pretrained(model_id)
|
8 |
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id)
|
9 |
model.eval()
|
10 |
|
|
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
model.to(device)
|
13 |
|
14 |
+
# logo (pakai yg huggingface dulu)
|
15 |
st.markdown(
|
16 |
"""
|
17 |
<style>
|
|
|
31 |
unsafe_allow_html=True,
|
32 |
)
|
33 |
|
|
|
34 |
st.title("VisionDerm")
|
35 |
st.write("Upload an image or use your camera to identify the skin condition.")
|
36 |
|
|
|
37 |
col1, col2 = st.columns([3, 2])
|
38 |
|
39 |
with col1:
|
40 |
+
# File uploader
|
41 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
42 |
+
# Camera input
|
43 |
camera_photo = st.camera_input("Take a photo")
|
44 |
prompt = 'Identify the skin condition?'
|
45 |
|
46 |
+
# Choose input image
|
47 |
input_image = None
|
48 |
if camera_photo:
|
49 |
input_image = Image.open(camera_photo)
|
|
|
52 |
|
53 |
with col2:
|
54 |
if input_image:
|
|
|
55 |
resized_image = input_image.resize((300, 300))
|
56 |
st.image(resized_image, caption="Selected Image (300x300)", use_container_width=True)
|
57 |
|
|
|
59 |
max_size = (512, 512)
|
60 |
processed_image = input_image.resize(max_size)
|
61 |
|
|
|
62 |
with st.spinner("Processing..."):
|
63 |
try:
|
|
|
64 |
inputs = processor(
|
65 |
text=prompt,
|
66 |
images=processed_image,
|
|
|
68 |
padding="longest"
|
69 |
).to(device)
|
70 |
|
|
|
71 |
default_max_tokens = 50 # Set a default value for max tokens
|
72 |
with torch.no_grad():
|
73 |
outputs = model.generate(**inputs, max_new_tokens=default_max_tokens)
|
74 |
|
|
|
75 |
decoded_output = processor.decode(outputs[0], skip_special_tokens=True)
|
76 |
if prompt in decoded_output:
|
77 |
decoded_output = decoded_output.replace(prompt, "").strip()
|
78 |
|
|
|
79 |
decoded_output = decoded_output.title()
|
80 |
|
|
|
81 |
st.success("Analysis Complete!")
|
82 |
st.write("**Model Output:**", decoded_output)
|
83 |
|
84 |
except Exception as e:
|
85 |
st.error(f"Error: {str(e)}")
|
86 |
|
87 |
+
st.markdown("---")
|
|
|
88 |
st.info("""
|
89 |
### Team: Mahasigma Berprestasi
|
90 |
- **Muhammad Karov Ardava Barus** ; 103052300001
|