Skip to content

Commit

Permalink
Move web app scripts into config map definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Davidson committed Oct 25, 2023
1 parent 216d968 commit 8c020c7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
53 changes: 52 additions & 1 deletion templates/ui/app-config-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,55 @@ metadata:
labels:
{{- include "azimuth-llm.labels" . | nindent 4 }}
data:
{{ (.Files.Glob "web-app/*").AsConfig | indent 2 }}
app.py: |
import huggingface_hub
from huggingface_hub import InferenceClient
import gradio as gr
from startup import wait_for_backend
backend_url = "http://{{ .Values.api.service.name }}.{{ .Release.Namespace }}.svc"
wait_for_backend(backend_url)
client = InferenceClient(model=backend_url)
def inference(message, history):
if message == "":
yield ""
partial_message = ""
try:
for token in client.text_generation(message, max_new_tokens=500, stream=True):
partial_message += token
# Strip text marker from generated output
partial_message = partial_message.replace('<|endoftext|>', '')
yield partial_message
except huggingface_hub.inference._text_generation.ValidationError as e:
raise gr.Error("Context length exceeded. Please clear the chat window.")
gr.ChatInterface(
inference,
chatbot=gr.Chatbot(
height=500,
show_copy_button=True,
),
title="Azimuth LLM",
description="This is the demo UI for the Azimuth LLM application.",
textbox=gr.Textbox(placeholder="Ask me anything...", container=False, scale=7),
retry_btn="Retry",
undo_btn="Undo",
clear_btn="Clear",
).queue().launch(server_name="0.0.0.0")
startup.py: |
import requests, time
def wait_for_backend(url):
ready = False
while not ready:
try:
ready = (requests.get(f'{url}/health').status_code == 200)
print('Waiting for backend API to start')
time.sleep(5)
except requests.exceptions.ConnectionError as e:
pass
return
42 changes: 0 additions & 42 deletions web-app/app.py

This file was deleted.

12 changes: 0 additions & 12 deletions web-app/startup.py

This file was deleted.

0 comments on commit 8c020c7

Please sign in to comment.