Skip to content

Commit

Permalink
Merge pull request #1 from tylerjrichards/main
Browse files Browse the repository at this point in the history
Updated Streamlit Example, deployed app link added to readme
  • Loading branch information
logan-markewich authored Mar 6, 2023
2 parents 0b752e4 + dedfe07 commit 0326b53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.envrc
.direnv
.streamlit/secrets.toml
.mypy_cache
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# llama_index_starter_pack
This repository provides very basic flask, streamlit, and docker examples for the [llama_index](https://github.com/jerryjliu/gpt_index) (FKA gpt_index) package.
This repository provides very basic flask, [Streamlit](https://llama-index.streamlit.app/), and docker examples for the [llama_index](https://github.com/jerryjliu/gpt_index) (FKA gpt_index) package.

If you need to quickly create a POC to impress your boss, start here!

Expand All @@ -20,13 +20,14 @@ There are two main example files
- creates a simple api that loads the text from the documents folder
- The "/query" endpoint accepts requests that contain a "text" parameter, which is used to query the index
- resturns string response containing the query answer

- streamlit_demo.py (localhost:8501)
- `streamlit run streamlit_demo.py`
- creates a simple UI using streamlit
- loads text from the documents folder (using `st.cache_resource`, so it only loads once)
- provides an input text-box and a button to run the query
- The string response is displayed after it finishes
- Want to see this example in action? Check it out [here](https://llama-index.streamlit.app/)


## Docker
Expand Down
18 changes: 9 additions & 9 deletions streamlit_demo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os

import streamlit as st
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader

# NOTE: for local testing only, do NOT deploy with your key hardcoded
os.environ['OPENAI_API_KEY'] = "your_key_here"
# to use this for yourself, create a file called .streamlit/secrets.toml with your api key
# Learn more about Streamlit on the docs: https://docs.streamlit.io/
os.environ["OPENAI_API_KEY"] = st.secrets["openai_api_key"]

import streamlit as st
from llama_index import SimpleDirectoryReader, GPTSimpleVectorIndex

index_name = "./index.json"
documents_folder = "./documents"
Expand Down Expand Up @@ -32,15 +35,12 @@ def query_index(_index, query_text):
index = initialize_index(index_name, documents_folder)


st.title("Llama Index")

st.header("Welcome to the Llama Index streamlit")

st.text("Please enter a query about Paul Graham's essay?")
st.title("🦙 Llama Index Demo 🦙")
st.header("Welcome to the Llama Index Streamlit Demo")
st.text("Please enter a query about Paul Graham's essays")

text = st.text_input("Query text:")

if st.button("Run Query") and text is not None:
response = query_index(index, text)
st.markdown(response)

0 comments on commit 0326b53

Please sign in to comment.