mrbeliever commited on
Commit
fc4d401
·
verified ·
1 Parent(s): c32572d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
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
- # Generate caption
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
- # Display the result
67
- if "error" in result:
68
- st.error(f"Error: {result['error']}")
69
- else:
70
- caption = result.get("messages", [{}])[-1].get("content", [{}])[0].get("text", "No caption generated.")
71
- st.subheader("Generated Caption")
72
- st.write(caption)
73
- elif not API_KEY:
74
- st.warning("Please set the `NEBIUS_API_KEY` environment variable.")
 
 
 
75
  else:
76
- st.info("Please upload an image.")
 
 
 
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")