Update app.py
Browse files
app.py
CHANGED
|
@@ -80,18 +80,24 @@ def main():
|
|
| 80 |
|
| 81 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if st.button("Send"):
|
| 84 |
system_prompt = "Your system prompt goes here"
|
| 85 |
|
| 86 |
-
if
|
| 87 |
-
|
| 88 |
-
image_data = uploaded_file.read()
|
| 89 |
-
caption = generate_image_caption(image_data)
|
| 90 |
-
|
| 91 |
-
if caption.startswith("Error"):
|
| 92 |
-
st.error(caption)
|
| 93 |
-
return
|
| 94 |
-
|
| 95 |
ai_response = next(run(caption, chat_history, system_prompt))
|
| 96 |
else:
|
| 97 |
ai_response = next(run(message, chat_history, system_prompt))
|
|
@@ -100,7 +106,3 @@ def main():
|
|
| 100 |
st.markdown(f"**AI:** {ai_response}", unsafe_allow_html=True)
|
| 101 |
|
| 102 |
chat_history.append((message, ai_response))
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
if __name__ == "__main__":
|
| 106 |
-
main()
|
|
|
|
| 80 |
|
| 81 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
|
| 82 |
|
| 83 |
+
if uploaded_file is not None:
|
| 84 |
+
# Display the uploaded image
|
| 85 |
+
st.image(uploaded_file, caption="Uploaded Image.", use_column_width=True)
|
| 86 |
+
|
| 87 |
+
# Process the image
|
| 88 |
+
image_data = uploaded_file.read()
|
| 89 |
+
caption = generate_image_caption(image_data)
|
| 90 |
+
|
| 91 |
+
if caption.startswith("Error"):
|
| 92 |
+
st.error(caption)
|
| 93 |
+
return
|
| 94 |
+
else:
|
| 95 |
+
caption = None
|
| 96 |
+
|
| 97 |
if st.button("Send"):
|
| 98 |
system_prompt = "Your system prompt goes here"
|
| 99 |
|
| 100 |
+
if caption is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
ai_response = next(run(caption, chat_history, system_prompt))
|
| 102 |
else:
|
| 103 |
ai_response = next(run(message, chat_history, system_prompt))
|
|
|
|
| 106 |
st.markdown(f"**AI:** {ai_response}", unsafe_allow_html=True)
|
| 107 |
|
| 108 |
chat_history.append((message, ai_response))
|
|
|
|
|
|
|
|
|
|
|
|