ardavey commited on
Commit
39a7b7a
·
verified ·
1 Parent(s): 7ab8248

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -37
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
- # File uploader for image
21
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
22
 
23
- # Text input for prompt
24
- input_text = st.text_input("Enter your prompt:", "Identify the skin condition?")
25
-
26
- # Slider for max tokens
27
- max_new_tokens = st.slider("Maximum Output Tokens:", 10, 100, 50)
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
- # Resize image for efficiency
37
- max_size = (512, 512)
38
- input_image = input_image.resize(max_size)
39
-
40
- # Prepare inputs
41
- with st.spinner("Processing..."):
42
- inputs = processor(
43
- text=input_text,
44
- images=input_image,
45
- return_tensors="pt",
46
- padding="longest"
47
- ).to(device)
48
-
49
- # Generate output
50
- with torch.no_grad():
51
- outputs = model.generate(**inputs, max_new_tokens=max_new_tokens)
52
-
53
- # Decode output
54
- decoded_output = processor.decode(outputs[0], skip_special_tokens=True)
55
-
56
- # Display result
57
- st.success("Analysis Complete!")
58
- st.write("**Model Output:**", decoded_output)
59
- except Exception as e:
60
- st.error(f"Error: {str(e)}")
 
 
 
 
 
 
 
 
 
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)}")