Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,41 +20,40 @@ if uploaded_file:
|
|
20 |
with st.expander("Image", expanded=True):
|
21 |
st.image(uploaded_file, caption=uploaded_file.name, use_column_width=True)
|
22 |
|
23 |
-
# Toggle for additional details input
|
24 |
-
show_details = st.checkbox("Add details about the image")
|
25 |
-
|
26 |
-
if show_details:
|
27 |
-
|
28 |
-
|
29 |
-
# Button to trigger the analysis
|
30 |
-
analyze_button = st.button("Analyse the MTSS Image")
|
31 |
-
|
32 |
-
if
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
else:
|
59 |
-
|
60 |
-
st.warning("Please upload an image.")
|
|
|
20 |
with st.expander("Image", expanded=True):
|
21 |
st.image(uploaded_file, caption=uploaded_file.name, use_column_width=True)
|
22 |
|
23 |
+
# Toggle for additional details input
|
24 |
+
show_details = st.checkbox("Add details about the image")
|
25 |
+
|
26 |
+
if show_details:
|
27 |
+
additional_details = st.text_area("Add any additional details or context about the image here:")
|
28 |
+
|
29 |
+
# Button to trigger the analysis
|
30 |
+
analyze_button = st.button("Analyse the MTSS Image")
|
31 |
+
|
32 |
+
if analyze_button:
|
33 |
+
with st.spinner("Analyzing the image..."):
|
34 |
+
base64_image = encode_image(uploaded_file)
|
35 |
+
prompt_text = (
|
36 |
+
"You are a highly knowledgeable accessibility expert. "
|
37 |
+
"Your task is to examine the following image in detail. "
|
38 |
+
"Provide a comprehensive, factual, and accurate explanation of what the image depicts. "
|
39 |
+
"Highlight key elements and their significance, and present your analysis in clear, well-structured format. "
|
40 |
+
"Create a detailed image caption in explaining in 150 words or less."
|
41 |
+
)
|
42 |
+
|
43 |
+
if show_details and additional_details:
|
44 |
+
prompt_text += f"\n\nAdditional Context Provided by the User:\n{additional_details}"
|
45 |
+
|
46 |
+
# Define the messages payload
|
47 |
+
messages = [{
|
48 |
+
"role": "user",
|
49 |
+
"content": [{"type": "text", "text": prompt_text}, {"type": "image_url", "image_url": f"data:image/jpeg;base64,{base64_image}"}]
|
50 |
+
}]
|
51 |
+
|
52 |
+
try:
|
53 |
+
# Make the request to OpenAI and handle streaming if required
|
54 |
+
response = openai.chat.completions.create(model="gpt-4-vision-preview", messages=messages, max_tokens=150)
|
55 |
+
st.write(response.choices[0].message.content)
|
56 |
+
except Exception as e:
|
57 |
+
st.error(f"An error occurred: {e}")
|
58 |
else:
|
59 |
+
st.warning("Please upload an image.")
|
|