2

I am trying to run this code sample code

import streamlit as st
from PIL import Image
import pandas as pandas
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
from clarifai_grpc.grpc.api.status import status_code_pb2
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import service_pb2_grpc
stub = service_pb2_grpc. V2Stub( ClarifaiChannel.get_grpc_channel())
st.title("IMAGE Demo")
st.header("Step 1: Enter an App Key")
key = st.text_input("App Key")
if key == '':
   st.warning("An app key has not been entered")
   st.stop()
else:
  st.write("App Key has been uploaded!")
file_data = st.file_uploader("Upload Image",type=\['jpg'\])
if file_data == None:
  st.warning("File needs to be uploaded")
  st.stop()
else:
  image = Image.open(file_data)
  st.image(image)
metadata = (('authorization', 'Key {}'.format(key)),)
request = service_pb2.PostModelOutputsRequest(model_id='9504135848be0dd2c39bdab0002f78e9',
inputs=\[ resources_pb2.Input(data=resources_pb2.Data(image=resources_pb2.Image(base64=file_data.getvalue()))) \])

response = stub.PostModelOutputs(request, metadata=metadata)
if response.status.code != status_code_pb2.SUCCESS:
   raise Exception("Request failed, status code: "+ str(response.status.code))
names = \[\]
confidences = \[\]
for concept in response.outputs\[0\].data.concepts:
   names.append(concept.name)
   confidences.append(concept.value)
   df = pandas.DataFrame({"Concept Name":names,"Model 
   Confidence":confidences
})

st.dataframe(df)

but i keep getting this error

Traceback (most recent call last):
  File "f:\IBMF project\web-design-course-restaurant-master - Copy\food.py", line 6, in <module>
    from clarifai_grpc.grpc.api import service_pb2, resources_pb2
  File "C:\Users\Ashraf\anaconda3\lib\site-packages\clarifai_grpc\grpc\api\service_pb2.py", line 16, in <module>
    from clarifai_grpc.grpc.api import resources_pb2 as proto_dot_clarifai_dot_api_dot_resources__pb2
  File "C:\Users\Ashraf\anaconda3\lib\site-packages\clarifai_grpc\grpc\api\resources_pb2.py", line 16, in <module>
    from clarifai_grpc.grpc.api.status import status_pb2 as proto_dot_clarifai_dot_api_dot_status_dot_status__pb2
  File "C:\Users\Ashraf\anaconda3\lib\site-packages\clarifai_grpc\grpc\api\status\status_pb2.py", line 15, in <module>
    from clarifai_grpc.grpc.auth.util import extension_pb2 as proto_dot_clarifai_dot_auth_dot_util_dot_extension__pb2
  File "C:\Users\Ashraf\anaconda3\lib\site-packages\clarifai_grpc\grpc\auth\util\extension_pb2.py", line 15, in <module>
    from clarifai_grpc.grpc.auth.scope import scope_pb2 as proto_dot_clarifai_dot_auth_dot_scope_dot_scope__pb2
  File "C:\Users\Ashraf\anaconda3\lib\site-packages\clarifai_grpc\grpc\auth\scope\scope_pb2.py", line 21, in <module>
    _S = DESCRIPTOR.enum_types_by_name['S']
AttributeError: 'NoneType' object has no attribute 'enum_types_by_name'

I installed all required packages for the cod to run I am using python 3.9.12 on Windows 10 I try to downgrade version of protobuf from 3.20.x to 3.15.6 when i try check the protobuf version and i got this

Name: protobuf
Version: 3.15.6
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author:
Author-email:
License: 3-Clause BSD License
Location: c:\users\ashraf\anaconda3\lib\site-packages
Requires: six
Required-by: streamlit, googleapis-common-protos, google-api-core, gcloud, clarifai-grpc

I don't understand what to do

Safee987
  • 39
  • 4
  • Please try bumping `protobuf` to e.g. [3.19.3](https://pypi.org/project/protobuf/3.19.3/) which is a dependency for the latest version of `clarifai-grpc` (`8.10.0`). You can use `python3 -m pip install protobuf=3.19.3`. – DazWilkin Nov 10 '22 at 21:29
  • Please consider editing your question and updating your Python code to reflect a correctly-indented Python source. It makes it more difficult for folks to help you if they have to spend time tidying up code. – DazWilkin Nov 10 '22 at 21:30
  • Does this answer your question? [Why do I get AttributeError: 'NoneType' object has no attribute 'something'?](https://stackoverflow.com/questions/8949252/why-do-i-get-attributeerror-nonetype-object-has-no-attribute-something) – Ulrich Eckhardt Nov 10 '22 at 21:57
  • And learn how to read stacktraces. It will help you much. – user99999 Nov 10 '22 at 22:34
  • @DazWilkin Thanks it worked however I get this error`ModuleNotFoundError: No module named 'grpc'` so I installed `pip install grpcio` but it did not solve the error – Safee987 Nov 11 '22 at 10:05
  • This is a different question and should be asked separately. `grpc` **should** be installed by `grprcio`. – DazWilkin Nov 11 '22 at 16:55

0 Answers0