Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
from PIL import Image
|
4 |
-
import base64
|
5 |
import io
|
6 |
|
7 |
# Streamlit page setup
|
8 |
st.set_page_config(page_title="MTSS Image Accessibility Alt Text Generator", layout="centered", initial_sidebar_state="auto")
|
9 |
|
10 |
-
# Add the image with a specified width
|
11 |
image_width = 300 # Set the desired width in pixels
|
12 |
st.image('MTSS.ai_Logo.png', width=image_width)
|
13 |
|
@@ -38,27 +37,24 @@ if uploaded_file:
|
|
38 |
else:
|
39 |
st.warning("Please upload an image.")
|
40 |
|
41 |
-
#
|
42 |
-
show_details = st.checkbox("Add details about the image.", value=False)
|
43 |
|
44 |
if show_details:
|
45 |
# Text input for additional details about the image
|
46 |
additional_details = st.text_area(
|
47 |
-
"
|
48 |
)
|
49 |
else:
|
50 |
additional_details = ""
|
51 |
|
52 |
-
# Toggle for modifying the prompt for complex images
|
53 |
-
complex_image = st.checkbox("Is this a complex image?", value=False)
|
54 |
-
|
55 |
# Button to trigger the analysis
|
56 |
analyze_button = st.button("Analyze the Image", type="secondary")
|
57 |
|
58 |
-
#
|
59 |
complex_image_prompt_text = (
|
60 |
"As an expert in image accessibility and alternative text, thoroughly describe the image caption provided. "
|
61 |
-
"Provide a
|
62 |
"Skip phrases like 'image of' or 'picture of.' "
|
63 |
"Your description should form a clear, well-structured, and factual paragraph that avoids bullet points, focusing on creating a seamless narrative."
|
64 |
)
|
@@ -103,20 +99,12 @@ if uploaded_file is not None and analyze_button:
|
|
103 |
else:
|
104 |
image_caption = caption_response[0]['generated_text']
|
105 |
|
106 |
-
#
|
107 |
-
|
108 |
-
prompt_text = complex_image_prompt_text
|
109 |
-
else:
|
110 |
-
prompt_text = (
|
111 |
-
"As an expert in image accessibility and alternative text, succinctly describe the image caption provided in less than 125 characters. "
|
112 |
-
"Provide a brief description using not more than 125 characters that conveys the essential information in three or fewer clear and concise sentences for use as alt text. "
|
113 |
-
"Skip phrases like 'image of' or 'picture of.' "
|
114 |
-
"Your description should form a clear, well-structured, and factual paragraph that avoids bullet points and newlines, focusing on creating a seamless narrative for accessibility purposes."
|
115 |
-
)
|
116 |
|
117 |
# Include additional details if provided
|
118 |
if additional_details:
|
119 |
-
prompt_text += f"\n\
|
120 |
|
121 |
# Create the prompt for the language model
|
122 |
full_prompt = f"{prompt_text}\n\nImage Caption: {image_caption}"
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
from PIL import Image
|
|
|
4 |
import io
|
5 |
|
6 |
# Streamlit page setup
|
7 |
st.set_page_config(page_title="MTSS Image Accessibility Alt Text Generator", layout="centered", initial_sidebar_state="auto")
|
8 |
|
9 |
+
# Add the logo image with a specified width
|
10 |
image_width = 300 # Set the desired width in pixels
|
11 |
st.image('MTSS.ai_Logo.png', width=image_width)
|
12 |
|
|
|
37 |
else:
|
38 |
st.warning("Please upload an image.")
|
39 |
|
40 |
+
# Option for adding additional details
|
41 |
+
show_details = st.checkbox("Add additional details about the image.", value=False)
|
42 |
|
43 |
if show_details:
|
44 |
# Text input for additional details about the image
|
45 |
additional_details = st.text_area(
|
46 |
+
"Provide specific information that is important to include in the alt text or reflect why the image is being used:"
|
47 |
)
|
48 |
else:
|
49 |
additional_details = ""
|
50 |
|
|
|
|
|
|
|
51 |
# Button to trigger the analysis
|
52 |
analyze_button = st.button("Analyze the Image", type="secondary")
|
53 |
|
54 |
+
# Prompt for complex image description
|
55 |
complex_image_prompt_text = (
|
56 |
"As an expert in image accessibility and alternative text, thoroughly describe the image caption provided. "
|
57 |
+
"Provide a detailed description using not more than 500 characters that conveys the essential information in eight or fewer clear and concise sentences. "
|
58 |
"Skip phrases like 'image of' or 'picture of.' "
|
59 |
"Your description should form a clear, well-structured, and factual paragraph that avoids bullet points, focusing on creating a seamless narrative."
|
60 |
)
|
|
|
99 |
else:
|
100 |
image_caption = caption_response[0]['generated_text']
|
101 |
|
102 |
+
# Use the complex image prompt text
|
103 |
+
prompt_text = complex_image_prompt_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
# Include additional details if provided
|
106 |
if additional_details:
|
107 |
+
prompt_text += f"\n\nAdditional context provided by the user:\n{additional_details}"
|
108 |
|
109 |
# Create the prompt for the language model
|
110 |
full_prompt = f"{prompt_text}\n\nImage Caption: {image_caption}"
|