Update app.py
Browse files
app.py
CHANGED
@@ -10,22 +10,22 @@ def get_image_concepts(image_bytes):
|
|
10 |
channel = ClarifaiChannel.get_grpc_channel()
|
11 |
stub = service_pb2_grpc.V2Stub(channel)
|
12 |
|
13 |
-
|
14 |
PAT = os.getenv('CLARIFAI_PAT')
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
metadata = (('authorization', 'Key ' + PAT),)
|
22 |
-
userDataObject = resources_pb2.UserAppIDSet(user_id=
|
23 |
|
24 |
post_model_outputs_response = stub.PostModelOutputs(
|
25 |
service_pb2.PostModelOutputsRequest(
|
26 |
user_app_id=userDataObject,
|
27 |
-
model_id=
|
28 |
-
version_id=
|
29 |
inputs=[
|
30 |
resources_pb2.Input(
|
31 |
data=resources_pb2.Data(
|
@@ -47,7 +47,6 @@ def get_image_concepts(image_bytes):
|
|
47 |
# Streamlit interface
|
48 |
st.title("Image Detection with Clarifai")
|
49 |
|
50 |
-
|
51 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
52 |
if uploaded_file is not None:
|
53 |
image_bytes = uploaded_file.getvalue()
|
@@ -66,24 +65,4 @@ if uploaded_file is not None:
|
|
66 |
for name in unique_names:
|
67 |
st.write(name)
|
68 |
else:
|
69 |
-
st.write("No unique items detected.")
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
"""
|
75 |
-
|
76 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
77 |
-
if uploaded_file is not None:
|
78 |
-
image_bytes = uploaded_file.getvalue()
|
79 |
-
regions = get_image_concepts(image_bytes)
|
80 |
-
for region in regions:
|
81 |
-
# Display each detected item
|
82 |
-
for concept in region.data.concepts:
|
83 |
-
name = concept.name
|
84 |
-
value = round(concept.value, 4)
|
85 |
-
st.write(f"{name}: {value}")
|
86 |
-
|
87 |
-
# Run this with `streamlit run your_script_name.py`
|
88 |
-
|
89 |
-
"""
|
|
|
10 |
channel = ClarifaiChannel.get_grpc_channel()
|
11 |
stub = service_pb2_grpc.V2Stub(channel)
|
12 |
|
|
|
13 |
PAT = os.getenv('CLARIFAI_PAT')
|
14 |
|
15 |
+
# Renamed variables
|
16 |
+
USER_ID_OBJECT = 'clarifai'
|
17 |
+
APP_ID_OBJECT = 'main'
|
18 |
+
MODEL_ID_OBJECT = 'general-image-detection'
|
19 |
+
MODEL_VERSION_ID_OBJECT = '1580bb1932594c93b7e2e04456af7c6f'
|
20 |
|
21 |
metadata = (('authorization', 'Key ' + PAT),)
|
22 |
+
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID_OBJECT, app_id=APP_ID_OBJECT)
|
23 |
|
24 |
post_model_outputs_response = stub.PostModelOutputs(
|
25 |
service_pb2.PostModelOutputsRequest(
|
26 |
user_app_id=userDataObject,
|
27 |
+
model_id=MODEL_ID_OBJECT,
|
28 |
+
version_id=MODEL_VERSION_ID_OBJECT,
|
29 |
inputs=[
|
30 |
resources_pb2.Input(
|
31 |
data=resources_pb2.Data(
|
|
|
47 |
# Streamlit interface
|
48 |
st.title("Image Detection with Clarifai")
|
49 |
|
|
|
50 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
51 |
if uploaded_file is not None:
|
52 |
image_bytes = uploaded_file.getvalue()
|
|
|
65 |
for name in unique_names:
|
66 |
st.write(name)
|
67 |
else:
|
68 |
+
st.write("No unique items detected.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|