-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cloudera/grpc
gRPC API surface plus response/requests datatype naming conventions
- Loading branch information
Showing
23 changed files
with
2,441 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
!streamlit run main.py --server.port $CDSW_APP_PORT --server.address 127.0.0.1 | ||
import subprocess | ||
import os | ||
|
||
CDSW_APP_PORT = os.environ.get("CDSW_APP_PORT") | ||
out = subprocess.run([f"bash ./bin/start-app-script.sh {CDSW_APP_PORT}"], shell=True, check=True) | ||
print(out) | ||
|
||
print("App start script is complete.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
|
||
# gRPC server will spawn on 50051 | ||
PORT=50051 | ||
|
||
{ # Try to start up the server | ||
echo "Starting up the gRPC server..." | ||
nohup python bin/start-grpc-server.py & | ||
} || { | ||
echo "gRPC server initialization script failed. Is there already a local server running in the pod?" | ||
} | ||
|
||
|
||
echo "Waiting 5 seconds..." | ||
sleep 5 | ||
|
||
|
||
# Start up the streamlit application | ||
echo "Starting up streamlit application..." | ||
streamlit run main.py --server.port $1 --server.address 127.0.0.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# start-grpc-server.py | ||
from concurrent import futures | ||
import logging | ||
import grpc | ||
from ft.proto import fine_tuning_studio_pb2_grpc | ||
from ft.service import FineTuningStudioApp | ||
from multiprocessing import Process | ||
import socket | ||
|
||
def start_server(blocking: bool = False): | ||
port = "50051" | ||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | ||
fine_tuning_studio_pb2_grpc.add_FineTuningStudioServicer_to_server(FineTuningStudioApp(), server=server) | ||
server.add_insecure_port("[::]:" + port) | ||
server.start() | ||
print("Server started, listening on " + port) | ||
|
||
if blocking: | ||
server.wait_for_termination() | ||
|
||
def is_port_in_use(port: int) -> bool: | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | ||
result = sock.connect_ex(('localhost', port)) | ||
return result == 0 | ||
|
||
|
||
port = 50051 | ||
if not is_port_in_use(port): | ||
print("Starting up the gRPC server.") | ||
# Start the gRPC server if it's not already running | ||
start_server(blocking=True) | ||
else: | ||
print("Server is already running.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
import streamlit as st | ||
import grpc | ||
|
||
from ft.api import * | ||
from ft.proto.fine_tuning_studio_pb2_grpc import FineTuningStudioStub | ||
|
||
|
||
with grpc.insecure_channel('localhost:50051') as channel: | ||
stub = FineTuningStudioStub(channel=channel) | ||
datasets: ListDatasetsResponse = stub.ListDatasets(ListDatasetsRequest()) | ||
print(datasets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.