Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -57,63 +57,6 @@
|
|
57 |
# "Your description should form a clear, well-structured, and factual paragraph that avoids bullet points, focusing on creating a seamless narrative that serves as effective alternative text for accessibility purposes."
|
58 |
# )
|
59 |
|
60 |
-
# if show_details and additional_details:
|
61 |
-
# prompt_text += (
|
62 |
-
# f"\n\nAdditional Context Provided by the User:\n{additional_details}"
|
63 |
-
# )
|
64 |
-
|
65 |
-
# # Create the payload for the completion request
|
66 |
-
# messages = [
|
67 |
-
# {
|
68 |
-
# "role": "user",
|
69 |
-
# "content": [
|
70 |
-
# {"type": "text", "text": prompt_text},
|
71 |
-
# {
|
72 |
-
# "type": "image_url",
|
73 |
-
# "image_url": f"data:image/jpeg;base64,{base64_image}",
|
74 |
-
# },
|
75 |
-
# ],
|
76 |
-
# }
|
77 |
-
# ]
|
78 |
-
|
79 |
-
# # Make the request to the OpenAI API
|
80 |
-
# try:
|
81 |
-
# # Without Stream
|
82 |
-
|
83 |
-
# # response = openai.chat.completions.create(
|
84 |
-
# # model="gpt-4-vision-preview", messages=messages, max_tokens=500, stream=False
|
85 |
-
# # )
|
86 |
-
|
87 |
-
# # Stream the response
|
88 |
-
# full_response = ""
|
89 |
-
# message_placeholder = st.empty()
|
90 |
-
# for completion in openai.chat.completions.create(
|
91 |
-
# model="gpt-4-vision-preview", messages=messages,
|
92 |
-
# max_tokens=250, stream=True
|
93 |
-
# ):
|
94 |
-
# # # Check if there is content to display
|
95 |
-
# # if completion.choices[0].delta.content is not None:
|
96 |
-
# # full_response += completion.choices[0].delta.content
|
97 |
-
# # message_placeholder.markdown(full_response + "▌")
|
98 |
-
# # # Final update to placeholder after the stream ends
|
99 |
-
# # message_placeholder.markdown(full_response) # stream text
|
100 |
-
|
101 |
-
# # Check if there is content to display
|
102 |
-
# if completion.choices[0].delta.content is not None:
|
103 |
-
# full_response += completion.choices[0].delta.content
|
104 |
-
|
105 |
-
# # Display the response in a text area
|
106 |
-
# st.text_area('Response:', value=full_response, height=400, key="response_text_area")
|
107 |
-
|
108 |
-
# st.success('Powered by MTSS GPT. AI can make mistakes. Consider checking important information.')
|
109 |
-
# except Exception as e:
|
110 |
-
# st.error(f"An error occurred: {e}")
|
111 |
-
# else:
|
112 |
-
# # Warnings for user action required
|
113 |
-
# if not uploaded_file and analyze_button:
|
114 |
-
# st.warning("Please upload an image.")
|
115 |
-
|
116 |
-
|
117 |
import streamlit as st
|
118 |
import base64
|
119 |
import openai
|
@@ -148,8 +91,7 @@ if uploaded_file:
|
|
148 |
show_details = st.toggle("Optional: Add details about the image. ", value=False)
|
149 |
|
150 |
# Toggle for modifying the prompt for complex images
|
151 |
-
complex_image = st.toggle("Is this a complex image? "
|
152 |
-
"By checking this box, it will inform MTSS.ai to create a robust description that exceeds the 125 character limit. You will add the description to a placeholder behind the image. Add 'Description in the content placeholder' in the alt text box.", value=False)
|
153 |
|
154 |
if show_details:
|
155 |
# Text input for additional details about the image, shown only if toggle is True
|
@@ -212,7 +154,7 @@ if uploaded_file is not None and analyze_button:
|
|
212 |
# Without Stream
|
213 |
|
214 |
# response = openai.chat.completions.create(
|
215 |
-
# model="gpt-4-vision-preview", messages=messages, max_tokens=
|
216 |
# )
|
217 |
|
218 |
# Stream the response
|
|
|
57 |
# "Your description should form a clear, well-structured, and factual paragraph that avoids bullet points, focusing on creating a seamless narrative that serves as effective alternative text for accessibility purposes."
|
58 |
# )
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
import streamlit as st
|
61 |
import base64
|
62 |
import openai
|
|
|
91 |
show_details = st.toggle("Optional: Add details about the image. ", value=False)
|
92 |
|
93 |
# Toggle for modifying the prompt for complex images
|
94 |
+
complex_image = st.toggle("Is this a complex image? ", value=False)
|
|
|
95 |
|
96 |
if show_details:
|
97 |
# Text input for additional details about the image, shown only if toggle is True
|
|
|
154 |
# Without Stream
|
155 |
|
156 |
# response = openai.chat.completions.create(
|
157 |
+
# model="gpt-4-vision-preview", messages=messages, max_tokens=250, stream=False
|
158 |
# )
|
159 |
|
160 |
# Stream the response
|