Spaces:
Running
Running
mrbeliever
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -58,21 +58,25 @@ if uploaded_image and API_KEY:
|
|
58 |
image.save(buffered, format="PNG")
|
59 |
image_base64 = base64.b64encode(buffered.getvalue()).decode()
|
60 |
|
61 |
-
#
|
62 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
63 |
-
st.write("Generating caption...")
|
64 |
-
result = generate_caption(image_base64, API_KEY)
|
65 |
|
66 |
-
#
|
67 |
-
if "
|
68 |
-
st.
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
else:
|
76 |
-
|
|
|
|
|
|
|
77 |
|
78 |
st.sidebar.write("Built with ❤️ by OpenAI GPT-4")
|
|
|
58 |
image.save(buffered, format="PNG")
|
59 |
image_base64 = base64.b64encode(buffered.getvalue()).decode()
|
60 |
|
61 |
+
# Show the uploaded image
|
62 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
|
|
|
|
63 |
|
64 |
+
# Add a button to trigger caption generation
|
65 |
+
if st.button("Generate Caption"):
|
66 |
+
st.write("Generating caption...")
|
67 |
+
result = generate_caption(image_base64, API_KEY)
|
68 |
+
|
69 |
+
# Display the result
|
70 |
+
if "error" in result:
|
71 |
+
st.error(f"Error: {result['error']}")
|
72 |
+
else:
|
73 |
+
caption = result.get("messages", [{}])[-1].get("content", [{}])[0].get("text", "No caption generated.")
|
74 |
+
st.subheader("Generated Caption")
|
75 |
+
st.write(caption)
|
76 |
else:
|
77 |
+
if not API_KEY:
|
78 |
+
st.warning("Please set the `NEBIUS_API_KEY` environment variable.")
|
79 |
+
else:
|
80 |
+
st.info("Please upload an image.")
|
81 |
|
82 |
st.sidebar.write("Built with ❤️ by OpenAI GPT-4")
|