Skip to content

Commit

Permalink
[Refactor] move sidebar to components (mmz-001#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmz-001 authored Feb 10, 2023
1 parent 28feec3 commit 187d8a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
39 changes: 39 additions & 0 deletions knowledge_gpt/components/sidebar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import streamlit as st


def set_openai_api_key(api_key: str):
st.session_state["OPENAI_API_KEY"] = api_key


def sidebar():
with st.sidebar:
st.markdown("# About")
st.markdown(
"📖KnowledgeGPT allows you to ask questions about your "
"documents and get accurate answers with instant citations. "
)
st.markdown(
"This tool is a work in progress. "
"You can contribute to the project on [GitHub](https://github.com/mmz-001/knowledge_gpt) "
"with your feedback and suggestions💡"
)
st.markdown("---")
st.markdown(
"## How to use\n"
"1. Enter your [OpenAI API key](https://platform.openai.com/account/api-keys) below🔑\n"
"2. Upload a pdf, docx, or txt file📄\n"
"3. Ask a question about the document💬\n"
)
api_key_input = st.text_input(
"OpenAI API Key",
type="password",
placeholder="Paste your OpenAI API key here (sk-...)",
help="You can get your API key from https://platform.openai.com/account/api-keys.",
value=st.session_state.get("OPENAI_API_KEY", ""),
)

if api_key_input:
set_openai_api_key(api_key_input)

st.markdown("---")
st.markdown("Made by [mmz_001](https://twitter.com/mm_sasmitha)")
37 changes: 2 additions & 35 deletions knowledge_gpt/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import streamlit as st
from components.sidebar import sidebar
from utils import (
parse_docx,
parse_pdf,
Expand All @@ -17,44 +18,10 @@ def clear_submit():
st.session_state["submit"] = False


def set_openai_api_key(api_key: str):
st.session_state["OPENAI_API_KEY"] = api_key


st.set_page_config(page_title="KnowledgeGPT", page_icon="📖", layout="wide")
st.header("📖KnowledgeGPT")

with st.sidebar:
st.markdown("# About")
st.markdown(
"📖KnowledgeGPT allows you to ask questions about your "
"documents and get accurate answers with instant citations. "
)
st.markdown(
"This tool is a work in progress. "
"You can contribute to the project on [GitHub](https://github.com/mmz-001/knowledge_gpt) "
"with your feedback and suggestions💡"
)
st.markdown("---")
st.markdown(
"## How to use\n"
"1. Enter your [OpenAI API key](https://platform.openai.com/account/api-keys) below🔑\n"
"2. Upload a pdf, docx, or txt file📄\n"
"3. Ask a question about the document💬\n"
)
api_key_input = st.text_input(
"OpenAI API Key",
type="password",
placeholder="Paste your OpenAI API key here (sk-...)",
help="You can get your API key from https://platform.openai.com/account/api-keys.",
value=st.session_state.get("OPENAI_API_KEY", ""),
)

if api_key_input:
set_openai_api_key(api_key_input)

st.markdown("---")
st.markdown("Made by [mmz_001](https://twitter.com/mm_sasmitha)")
sidebar()

uploaded_file = st.file_uploader(
"Upload a pdf, docx, or txt file",
Expand Down

0 comments on commit 187d8a7

Please sign in to comment.