Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,44 +17,51 @@ model.to(device)
|
|
17 |
st.title("Skin Condition Identifier")
|
18 |
st.write("Upload an image and provide a text prompt to identify the skin condition.")
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
# Process and display the result when the button is clicked
|
30 |
-
if uploaded_file is not None and st.button("Analyze"):
|
31 |
-
try:
|
32 |
-
# Open the uploaded image
|
33 |
input_image = Image.open(uploaded_file).convert("RGB")
|
34 |
st.image(input_image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
st.title("Skin Condition Identifier")
|
18 |
st.write("Upload an image and provide a text prompt to identify the skin condition.")
|
19 |
|
20 |
+
# Column layout for input and display
|
21 |
+
col1, col2 = st.columns([3, 2])
|
22 |
|
23 |
+
with col1:
|
24 |
+
# File uploader for image
|
25 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
26 |
+
|
27 |
+
# Display uploaded image (if any)
|
28 |
+
if uploaded_file:
|
|
|
|
|
|
|
|
|
29 |
input_image = Image.open(uploaded_file).convert("RGB")
|
30 |
st.image(input_image, caption="Uploaded Image", use_column_width=True)
|
31 |
+
|
32 |
+
# Text input for prompt
|
33 |
+
input_text = st.text_input("Enter your prompt:", "Identify the skin condition?")
|
34 |
|
35 |
+
with col2:
|
36 |
+
# Process and display the result when the button is clicked
|
37 |
+
if uploaded_file and st.button("Analyze"):
|
38 |
+
if not input_text.strip():
|
39 |
+
st.error("Please provide a valid prompt!")
|
40 |
+
else:
|
41 |
+
try:
|
42 |
+
# Resize image for efficiency
|
43 |
+
max_size = (512, 512)
|
44 |
+
input_image = input_image.resize(max_size)
|
45 |
+
|
46 |
+
# Prepare inputs
|
47 |
+
with st.spinner("Processing..."):
|
48 |
+
inputs = processor(
|
49 |
+
text=input_text,
|
50 |
+
images=input_image,
|
51 |
+
return_tensors="pt",
|
52 |
+
padding="longest"
|
53 |
+
).to(device)
|
54 |
+
|
55 |
+
# Generate output with default max_new_tokens
|
56 |
+
default_max_tokens = 50 # Set a default value for max tokens
|
57 |
+
with torch.no_grad():
|
58 |
+
outputs = model.generate(**inputs, max_new_tokens=default_max_tokens)
|
59 |
+
|
60 |
+
# Decode output
|
61 |
+
decoded_output = processor.decode(outputs[0], skip_special_tokens=True)
|
62 |
+
|
63 |
+
# Display result
|
64 |
+
st.success("Analysis Complete!")
|
65 |
+
st.write("**Model Output:**", decoded_output)
|
66 |
+
except Exception as e:
|
67 |
+
st.error(f"Error: {str(e)}")
|