Skip to content

Commit 3a50390

Browse files
committed
working demo with working inference services and eveeryhting
1 parent dc3d7f2 commit 3a50390

File tree

7 files changed

+195
-28
lines changed

7 files changed

+195
-28
lines changed

authbackup.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
apiVersion: v1
2+
items:
3+
- apiVersion: security.istio.io/v1beta1
4+
kind: AuthorizationPolicy
5+
metadata:
6+
annotations:
7+
metacontroller.k8s.io/last-applied-configuration: '{"apiVersion":"security.istio.io/v1beta1","kind":"AuthorizationPolicy","metadata":{"labels":{"controller-uid":"087b40d8-1cdb-4c27-93f1-240663a11120"},"name":"ml-pipeline-visualizationserver","namespace":"christensenc3526"},"spec":{"rules":[{"from":[{"source":{"principals":["cluster.local/ns/kubeflow/sa/ml-pipeline"]}}]}],"selector":{"matchLabels":{"app":"ml-pipeline-visualizationserver"}}}}'
8+
creationTimestamp: "2024-02-01T16:18:49Z"
9+
generation: 1
10+
labels:
11+
controller-uid: 087b40d8-1cdb-4c27-93f1-240663a11120
12+
name: ml-pipeline-visualizationserver
13+
namespace: christensenc3526
14+
ownerReferences:
15+
- apiVersion: v1
16+
blockOwnerDeletion: true
17+
controller: true
18+
kind: Namespace
19+
name: christensenc3526
20+
uid: 087b40d8-1cdb-4c27-93f1-240663a11120
21+
resourceVersion: "1287486"
22+
uid: 225ad4f4-6e86-429b-a8bd-de0239d9588b
23+
spec:
24+
rules:
25+
- from:
26+
- source:
27+
principals:
28+
- cluster.local/ns/kubeflow/sa/ml-pipeline
29+
selector:
30+
matchLabels:
31+
app: ml-pipeline-visualizationserver
32+
- apiVersion: security.istio.io/v1beta1
33+
kind: AuthorizationPolicy
34+
metadata:
35+
annotations:
36+
role: admin
37+
user: christensenc3526@gmail.com
38+
name: ns-owner-access-istio
39+
namespace: christensenc3526
40+
ownerReferences:
41+
- apiVersion: kubeflow.org/v1
42+
blockOwnerDeletion: true
43+
controller: true
44+
kind: Profile
45+
name: christensenc3526
46+
uid: 83504f57-d3c3-406d-8c6b-cd5442091687
47+
resourceVersion: "1287526"
48+
uid: 2365c954-ebef-417b-b333-6ff4a8bc826f
49+
spec:
50+
rules:
51+
- from:
52+
- source:
53+
principals:
54+
- cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account
55+
- cluster.local/ns/kubeflow/sa/ml-pipeline-ui
56+
when:
57+
- key: request.headers[x-goog-authenticated-user-email]
58+
values:
59+
- accounts.google.com:christensenc3526@gmail.com
60+
- when:
61+
- key: source.namespace
62+
values:
63+
- christensenc3526
64+
- to:
65+
- operation:
66+
paths:
67+
- /healthz
68+
- /metrics
69+
- /wait-for-drain
70+
- from:
71+
- source:
72+
principals:
73+
- cluster.local/ns/kubeflow/sa/notebook-controller-service-account
74+
to:
75+
- operation:
76+
methods:
77+
- GET
78+
paths:
79+
- '*/api/kernels'
80+
kind: List
81+
metadata:
82+
resourceVersion: ""

dockerfiles/frontend/dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ ADD src/requirements.txt /workspace/requirements.txt
44
RUN pip install -r requirements.txt
55
ADD src/app.py src/theme.py images/app-header.png /workspace/
66
ENV HOME=/workspace
7-
EXPOSE 80
7+
EXPOSE 8080
88
CMD [ "python3" , "/workspace/app.py" ]

dockerfiles/frontend/src/app.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import json
22
import requests
3-
3+
from fastapi import FastAPI
44
import gradio as gr
55
from theme import TileDBTheme
6-
7-
6+
import os
7+
import uvicorn
8+
app = FastAPI()
9+
CUSTOM_PATH = os.environ.get("CUSTOM_PATH", "/tiledb")
810
DOMAIN_NAME = "svc.cluster.local"
911
NAMESPACE = open("/var/run/secrets/kubernetes.io/serviceaccount/namespace", "r").read()
1012
DEPLOYMENT_NAME = "llm"
1113
MODEL_NAME = DEPLOYMENT_NAME
1214
SVC = f"{DEPLOYMENT_NAME}-transformer.{NAMESPACE}.{DOMAIN_NAME}"
13-
URL = f"https://{SVC}/v1/models/{MODEL_NAME}:predict"
15+
URL = f"http://{SVC}/v1/models/{MODEL_NAME}:predict"
1416

1517
SYSTEM_MESSAGE = "You are an AI assistant. You will be given a task. You must generate a detailed answer."
1618
INSTRUCTION = "Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer."
1719

1820
example_questions = [
19-
["What is TileDB?"],
20-
["What makes TileDB a great vector database?"],
21-
["Does the TileDB vector database use sparse or dense arrays?"]
21+
["How does this demo work?"],
22+
["Why TileDB for vector databases?"],
23+
["Do vector datatbases use dense or sparse arrays?"]
2224
]
2325

2426

@@ -53,8 +55,8 @@ def llm_service(question, system, instruction, temperature, num_docs, max_tokens
5355
return json.loads(response.text)["predictions"][0]
5456

5557

56-
if __name__ == "__main__":
57-
with gr.Blocks(theme=TileDBTheme()) as app:
58+
def create_gradio_app():
59+
with gr.Blocks(theme=TileDBTheme()) as demo:
5860
gr.Markdown("![ai-enabled-search](file/app-header.png)")
5961
with gr.Row():
6062
question = gr.Textbox(label="Question", autofocus=True)
@@ -130,5 +132,15 @@ def llm_service(question, system, instruction, temperature, num_docs, max_tokens
130132
outputs=[question, system, instruction, temperature, num_docs,
131133
max_tokens, top_k, top_p, context_check, output])
132134

133-
app.launch(server_name="0.0.0.0", server_port=8080)
135+
return demo
134136

137+
138+
@app.get("/")
139+
def read_main():
140+
return {"message": "This is the main app. Access the Gradio interface at /tiledb"}
141+
142+
if __name__ == "__main__":
143+
io=create_gradio_app()
144+
gradio_app = gr.routes.App.create_app(io)
145+
app.mount(CUSTOM_PATH, gradio_app)
146+
uvicorn.run(app, host="0.0.0.0", port=8080)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
gradio==3.44.4
2+
fastapi
3+
uvicorn

dockerfiles/frontend/src/theme.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from gradio.themes.utils import colors
44

55
# Define TileDB colors here
6-
TILEDB_PRIMARY = "#2A7DE1" # Example primary color
6+
TILEDB_PRIMARY = "##2a7de1" # Example primary color
77
TILEDB_SECONDARY = "#F3F4F6" # Example secondary color
88
TILEDB_BACKGROUND = "#374151" # Example background color
99
TILEDB_TEXT = "#6E707A" # Example text color
@@ -16,8 +16,8 @@ class TileDBTheme(Base):
1616
def __init__(
1717
self,
1818
*,
19-
primary_hue: Union[colors.Color, str] = TILEDB_PRIMARY,
20-
neutral_hue: Union[colors.Color, str] = TILEDB_BACKGROUND,
19+
primary_hue: Union[colors.Color, str] = colors.slate,
20+
neutral_hue: Union[colors.Color, str] = colors.cyan,
2121
):
2222
super().__init__(
2323
primary_hue=primary_hue,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from fastapi import FastAPI
2+
import gradio as gr
3+
import os
4+
5+
app = FastAPI()
6+
CUSTOM_PATH = os.environ.get("CUSTOM_PATH", "/tiledb")
7+
8+
# Define the Gradio interface function
9+
def greet(name, intensity):
10+
return "Hello " * intensity + name + "!"
11+
12+
# Create the Gradio interface
13+
io = gr.Interface(fn=greet, inputs=["text", "slider"], outputs="text")
14+
15+
# Create a Gradio app from the interface
16+
gradio_app = gr.routes.App.create_app(io)
17+
18+
# Mount the Gradio app on the custom path within the FastAPI application
19+
app.mount(CUSTOM_PATH, gradio_app)
20+
21+
@app.get("/")
22+
def read_main():
23+
return {"message": "This is the main app. Access the Gradio interface at /tiledb"}
24+
25+
if __name__ == "__main__":
26+
import uvicorn
27+
uvicorn.run(app, host="0.0.0.0", port=8080)
28+

manifests/frontend.yml

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,82 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: llm-deployment
4+
name: demo-deployment
5+
namespace: christensenc3526
56
labels:
6-
app: llm
7+
app: demo
78
spec:
89
replicas: 1
910
selector:
1011
matchLabels:
11-
app: llm
12+
app: demo
1213
template:
1314
metadata:
1415
labels:
15-
app: llm
16+
app: demo
1617
spec:
1718
containers:
18-
- name: llm-container
19-
image: <your-docker-image-name>:<tag>
19+
- name: demo-app
20+
image: chasechristensen/tiledb_demo_frontend:v22
2021
ports:
21-
- containerPort: 8080
22-
env:
23-
- name: GRADIO_SERVER_PORT
24-
value: "8080"
25-
- name: GRADIO_SERVER_NAME
26-
value: "0.0.0.0"
22+
- name: http
23+
containerPort: 8080
24+
protocol: TCP
2725
---
2826
apiVersion: v1
2927
kind: Service
3028
metadata:
31-
name: llm-transformer-default
29+
name: demo
30+
namespace: christensenc3526
3231
spec:
3332
selector:
34-
app: llm
33+
app: demo
3534
ports:
3635
- protocol: TCP
3736
port: 80
3837
targetPort: 8080
38+
name: http
39+
---
40+
apiVersion: networking.istio.io/v1beta1
41+
kind: VirtualService
42+
metadata:
43+
name: tiledb-virtual-service
44+
namespace: christensenc3526 # Match this with your service's namespace
45+
spec:
46+
gateways:
47+
- kubeflow-gateway
48+
hosts:
49+
- '*'
50+
http:
51+
- match:
52+
- uri:
53+
prefix: /tiledb
54+
rewrite:
55+
uri: /
56+
route:
57+
- destination:
58+
host: demo.christensenc3526.svc.cluster.local
59+
port:
60+
number: 80
61+
62+
---
63+
64+
apiVersion: security.istio.io/v1beta1
65+
kind: AuthorizationPolicy
66+
metadata:
67+
name: demo-service-external-access
68+
namespace: christensenc3526
69+
spec:
70+
action: ALLOW
71+
rules:
72+
- to:
73+
- operation:
74+
methods: ["GET", "POST"] # Adjust based on the methods your service requires
75+
paths: ["/tiledb/*"] # Adjust if your service listens on different paths
76+
- from:
77+
- source:
78+
requestPrincipals: ["*"] # Allows access from any authenticated user (consider narrowing this down)
79+
selector:
80+
matchLabels:
81+
app: demo
3982

0 commit comments

Comments
 (0)