eaglelandsonce commited on
Commit
a7013cf
β€’
1 Parent(s): 250bb0c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +46 -0
  2. requirements.txt +4 -0
  3. utils.py +10 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import generate_vector
3
+
4
+ # Applying Styling
5
+ st.markdown("""
6
+ <style>
7
+ div.stButton > button:first-child {
8
+ background-color: #0a99fa;
9
+ color:#ffffff;
10
+ }
11
+ div.stButton > button:hover {
12
+ background-color: #ffffff;
13
+ color:#0a99fa;
14
+ }
15
+ </style>""", unsafe_allow_html=True)
16
+
17
+ # Creating Session State Variable
18
+ if 'API_Key' not in st.session_state:
19
+ st.session_state['API_Key'] = ''
20
+
21
+ st.title('πŸ“ Vector Creator')
22
+
23
+ # Sidebar to capture the OpenAi API key
24
+ st.sidebar.title("πŸ—οΈ")
25
+ st.session_state['API_Key'] = st.sidebar.text_input("Paste in your OPENAI API key?", type="password")
26
+ st.sidebar.markdown('Vector Generator: Input some text to view its vector. Designed for my cloud Meetup as a demonstration of simple chaining using LangChain. Check out our Cloud Meetup at https://www.meetup.com/florence-aws-user-group-meetup It is free to join!')
27
+
28
+ # Captures User Inputs
29
+ prompt = st.text_input('Please add some text to vectorize', key="prompt")
30
+
31
+ submit = st.button("Generate a Vector for me")
32
+
33
+ if submit:
34
+
35
+ if st.session_state['API_Key']:
36
+ text_embedding = generate_vector(prompt, st.session_state['API_Key'])
37
+ # Let's generate the script
38
+ st.success('You are now in 1536 dimensional space, how does it feel?')
39
+
40
+ # Display Title
41
+ st.subheader("Vector:πŸ”")
42
+ st.write(text_embedding)
43
+
44
+
45
+ else:
46
+ st.error("Please provide your OpenAI API key in the left column.....")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ langchain
2
+ Openai
3
+ tiktoken
4
+ Streamlit
utils.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from langchain.embeddings import OpenAIEmbeddings
3
+
4
+
5
+ # Function to generate title and Logline from simple chaining
6
+ def generate_vector(prompt, api_key):
7
+ os.environ["OPENAI_API_KEY"] = api_key
8
+ embeddings = OpenAIEmbeddings()
9
+ text_embedding = embeddings.embed_query(prompt)
10
+ return text_embedding