diff --git a/.github/workflows/deploy-on-merge-to-main.yml b/.github/workflows/deploy-on-merge-to-main.yml index 48d7a07..04f0ef4 100644 --- a/.github/workflows/deploy-on-merge-to-main.yml +++ b/.github/workflows/deploy-on-merge-to-main.yml @@ -25,9 +25,12 @@ jobs: - name: Set Fly secrets run: | flyctl secrets set --stage --app "prod-yral-nsfw-classification" "SERVICE_CRED=$(jq -n -c "${SERVICE_CRED}")" + flyctl secrets set --stage --app "prod-yral-nsfw-classification" "PUBLIC_KEY_TO_VERIFY_INCOMING_CALLS_FROM_FRONTEND_LEPTOS_SSR_SERVICE=${PUBLIC_KEY_TO_VERIFY_INCOMING_CALLS_FROM_FRONTEND_LEPTOS_SSR_SERVICE}" env: FLY_API_TOKEN: ${{ secrets.FLY_IO_DEPLOY_TOKEN }} SERVICE_CRED: ${{ secrets.GOOGLE_CLOUD_EVENTS_BQ_SERVICE_ACCOUNT_KEY_JSON }} + PUBLIC_KEY_TO_VERIFY_INCOMING_CALLS_FROM_FRONTEND_LEPTOS_SSR_SERVICE: + ${{ env.PUBLIC_KEY_TO_VERIFY_INCOMING_CALLS_FROM_FRONTEND_LEPTOS_SSR_SERVICE }} - name: Check fly status run: | diff --git a/ping_server.py b/ping_server.py index 3919a30..772efa0 100644 --- a/ping_server.py +++ b/ping_server.py @@ -3,13 +3,14 @@ import nsfw_detector_pb2_grpc import os import jwt +import base64 token_fpath = "/Users/jaydhanwant/Documents/SS/nsfw_jwt_token.txt" with open(token_fpath, 'r') as f: _JWT_TOKEN = f.read() -# server_url = 'prod-yral-nsfw-classification.fly.dev:443' -server_url = 'yral-nsfw-classification.fly.dev:443' +server_url = 'prod-yral-nsfw-classification.fly.dev:443' +# server_url = 'yral-nsfw-classification.fly.dev:443' # Load the private key from a path specified in an environment variable def run(): @@ -20,11 +21,25 @@ def run(): # Test video ID (replace with an actual video ID for testing) video_id = "00034f1c9c9148388bf6873776222535" + image_url = "https://img-cdn.pixlr.com/image-generator/history/65bb506dcb310754719cf81f/ede935de-1138-4f66-8ed7-44bd16efc709/medium.webp" + # Test image path for byte64 + image_path = "/Users/jaydhanwant/Downloads/WhatsApp Image 2024-08-29 at 13.18.09.jpeg" + try: - print("Sending request to server") + print("Sending video ID request to server") metadata = [('authorization', f'Bearer {_JWT_TOKEN}')] - response = stub.DetectNSFWVideoId(nsfw_detector_pb2.NSFWDetectorRequestVideoId(video_id=video_id), metadata=metadata) - print(response) + video_response = stub.DetectNSFWVideoId(nsfw_detector_pb2.NSFWDetectorRequestVideoId(video_id=video_id), metadata=metadata) + print(video_response) + + # print("Sending image URL request to server") + # url_response = stub.DetectNSFWURL(nsfw_detector_pb2.NSFWDetectorRequestURL(url=image_url), metadata=metadata) + # print(url_response) + + print("Sending image to byte64 request to server") + with open(image_path, "rb") as image_file: + image_byte64 = base64.b64encode(image_file.read()).decode('utf-8') + byte64_response = stub.DetectNSFWImg(nsfw_detector_pb2.NSFWDetectorRequestImg(image=image_byte64), metadata=metadata) + print(byte64_response) except grpc.RpcError as e: print(f"RPC failed: {e}") diff --git a/server.py b/server.py index 77fb6e8..09c9fd2 100644 --- a/server.py +++ b/server.py @@ -35,10 +35,11 @@ _AUTH_HEADER_KEY = "authorization" -_PUBLIC_KEY = consts.NSFW_JWT_PUB_KEY -_JWT_PAYLOAD = { +# _PUBLIC_KEY = consts.NSFW_JWT_PUB_KEY +_PUBLIC_KEY = os.environ.get("PUBLIC_KEY_TO_VERIFY_INCOMING_CALLS_FROM_FRONTEND_LEPTOS_SSR_SERVICE") +_JWT_PAYLOAD = { "sub": "yral-nsfw-detector-server", - "company": "gobazzinga", + "company": "Yral", } # downloading model artifacts