Spaces:
Build error
Build error
Update pages/4_TwoImageDescriptor.py
Browse files- pages/4_TwoImageDescriptor.py +26 -13
pages/4_TwoImageDescriptor.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import base64
|
| 3 |
-
import anthropic
|
| 4 |
-
|
| 5 |
-
# Assuming anthropic is a package that provides an Anthropic client for interacting with Claude
|
| 6 |
-
# and it's installed or defined somewhere in your project
|
| 7 |
-
from anthropic import Anthropic
|
| 8 |
|
| 9 |
def image_to_base64(image):
|
| 10 |
"""Convert the uploaded image to base64."""
|
|
@@ -51,19 +47,36 @@ def describe_image(image, api_key):
|
|
| 51 |
return message.content
|
| 52 |
|
| 53 |
def main():
|
| 54 |
-
st.title("Image Description with Claude")
|
| 55 |
|
| 56 |
api_key = st.text_input("Enter your Claude API Key:", type="password")
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
if st.button("Describe
|
| 61 |
-
if api_key:
|
| 62 |
-
description = describe_image(uploaded_image, api_key)
|
| 63 |
-
st.text("Description from Claude:")
|
| 64 |
-
st.write(description)
|
| 65 |
-
else:
|
| 66 |
st.error("Please enter a valid API key.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
main()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import base64
|
| 3 |
+
from anthropic import Anthropic # Assuming anthropic is a package for interacting with Claude
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def image_to_base64(image):
|
| 6 |
"""Convert the uploaded image to base64."""
|
|
|
|
| 47 |
return message.content
|
| 48 |
|
| 49 |
def main():
|
| 50 |
+
st.title("Image Description with Claude 3 Opus")
|
| 51 |
|
| 52 |
api_key = st.text_input("Enter your Claude API Key:", type="password")
|
| 53 |
+
|
| 54 |
+
st.header("Upload Images")
|
| 55 |
+
col1, col2 = st.columns(2)
|
| 56 |
|
| 57 |
+
with col1:
|
| 58 |
+
view_image = st.file_uploader("Upload View Image", type=["jpg", "jpeg", "png"], key="view")
|
| 59 |
+
with col2:
|
| 60 |
+
buffer_image = st.file_uploader("Upload Buffer Image", type=["jpg", "jpeg", "png"], key="buffer")
|
| 61 |
|
| 62 |
+
if st.button("Describe Images"):
|
| 63 |
+
if not api_key:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
st.error("Please enter a valid API key.")
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
if view_image is not None:
|
| 68 |
+
view_description = describe_image(view_image, api_key)
|
| 69 |
+
st.text("View Image Description from Claude:")
|
| 70 |
+
st.write(view_description)
|
| 71 |
+
else:
|
| 72 |
+
st.error("Please upload a View image.")
|
| 73 |
+
|
| 74 |
+
if buffer_image is not None:
|
| 75 |
+
buffer_description = describe_image(buffer_image, api_key)
|
| 76 |
+
st.text("Buffer Image Description from Claude:")
|
| 77 |
+
st.write(buffer_description)
|
| 78 |
+
else:
|
| 79 |
+
st.error("Please upload a Buffer image.")
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
main()
|