John Graham Reynolds commited on
Commit
d43b410
·
1 Parent(s): 7485fe3

add code for testing databricks access outside of databricks

Browse files
Files changed (2) hide show
  1. app.py +85 -13
  2. style.css +3 -0
app.py CHANGED
@@ -1,20 +1,92 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
- from PIL import Image
 
4
 
5
- pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
 
 
 
6
 
7
- st.title("Hot Dog? Or Not?")
 
 
 
8
 
9
- file_name = st.file_uploader("Upload a hot dog candidate image")
 
 
 
 
 
 
 
 
 
10
 
11
- if file_name is not None:
12
- col1, col2 = st.columns(2)
13
 
14
- image = Image.open(file_name)
15
- col1.image(image, use_column_width=True)
16
- predictions = pipeline(image)
 
 
 
 
17
 
18
- col2.header("Probabilities")
19
- for p in predictions:
20
- col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import os
3
+ from mlflow import deployments
4
+ from databricks.vector_search.client import VectorSearchClient
5
 
6
+ DATABRICKS_HOST = os.environ.get("DATABRICKS_HOST")
7
+ DATABRICKS_API_TOKEN = os.environ.get("DATABRICKS_API_TOKEN")
8
+ VS_ENDPOINT_NAME = os.environ.get("VS_ENDPOINT_NAME")
9
+ VS_INDEX_NAME = os.environ.get("VS_INDEX_NAME")
10
 
11
+ if DATABRICKS_HOST is None:
12
+ raise ValueError("DATABRICKS_HOST environment variable must be set")
13
+ if DATABRICKS_API_TOKEN is None:
14
+ raise ValueError("DATABRICKS_API_TOKEN environment variable must be set")
15
 
16
+ TITLE = "VUMC Chatbot"
17
+ DESCRIPTION="The first generation VUMC chatbot with knowledge of Vanderbilt specific terms."
18
+ EXAMPLE_PROMPTS = [
19
+ "Write a short story about a robot that has a nice day.",
20
+ "In a table, what are some of the most common misconceptions about birds?",
21
+ "Give me a recipe for vegan banana bread.",
22
+ "Code a python function that can run merge sort on a list.",
23
+ "Give me the character profile of a gumdrop obsessed knight in JSON.",
24
+ "Write a rap battle between Alan Turing and Claude Shannon.",
25
+ ]
26
 
27
+ st.set_page_config(layout="wide")
28
+ st.title(TITLE)
29
 
30
+ # test env vars get output correctly - do we need to configure PAT access further?
31
+ st.markdown(DESCRIPTION)
32
+ st.markdown("\n")
33
+ st.write(DATABRICKS_HOST)
34
+ st.markdown("\n")
35
+ st.write(VS_ENDPOINT_NAME)
36
+ st.markdown("\n")
37
 
38
+ # use this to format later
39
+ # with open("style.css") as css:
40
+ # st.markdown( f'<style>{css.read()}</style>' , unsafe_allow_html= True)
41
+
42
+ vsc = VectorSearchClient()
43
+
44
+ question = "What is the data lake?"
45
+ # question_2 = "What does EDW stand for?"
46
+ # question_3 = "What does AIDET stand for?"
47
+
48
+ deploy_client = deployments.get_deploy_client("databricks")
49
+ response = deploy_client.predict(endpoint="databricks-bge-large-en", inputs={"input": [question]})
50
+ embeddings = [e['embedding'] for e in response.data]
51
+
52
+ results = vsc.get_index(VS_ENDPOINT_NAME, VS_INDEX_NAME).similarity_search(
53
+ query_vector=embeddings[0],
54
+ columns=["name", "description"],
55
+ num_results=5)
56
+
57
+ st.write(results)
58
+
59
+
60
+ # print(results)
61
+ # print("---------------------------------------")
62
+ # vumc_terms = results.get('result', {}).get('data_array', [])
63
+ # print(vumc_terms)
64
+
65
+
66
+ # DBRX mainbody minus functions
67
+
68
+ # main = st.container()
69
+ # with main:
70
+ # history = st.container(height=400)
71
+ # with history:
72
+ # for message in st.session_state["messages"]:
73
+ # avatar = None
74
+ # if message["role"] == "assistant":
75
+ # avatar = MODEL_AVATAR_URL
76
+ # with st.chat_message(message["role"],avatar=avatar):
77
+ # if message["content"] is not None:
78
+ # st.markdown(message["content"])
79
+ # if message["error"] is not None:
80
+ # st.error(message["error"],icon="🚨")
81
+ # if message["warning"] is not None:
82
+ # st.warning(message["warning"],icon="⚠️")
83
+
84
+ # if prompt := st.chat_input("Type a message!", max_chars=1000):
85
+ # handle_user_input(prompt)
86
+ # st.markdown("\n") #add some space for iphone users
87
+
88
+ # with st.sidebar:
89
+ # with st.container():
90
+ # st.title("Examples")
91
+ # for prompt in EXAMPLE_PROMPTS:
92
+ # st.button(prompt, args=(prompt,), on_click=handle_user_input)
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .st-emotion-cache-1tpusnk a{
2
+ color: #FF5F46;
3
+ }