Skip to content

Commit

Permalink
frontend
Browse files Browse the repository at this point in the history
Updated home page of the Streamlit app
  • Loading branch information
HemanthSai7 committed Dec 14, 2023
1 parent d3a5b6a commit e6a8680
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 15 deletions.
2 changes: 2 additions & 0 deletions frontend/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .authors import *
from .user_greetings import *
13 changes: 13 additions & 0 deletions frontend/components/authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
import streamlit as st


def authors():
st.sidebar.divider()
st.sidebar.info(
"""
Follow me on:
Github → [@HemanthSai7](https://github.com/HemanthSai7)
"""
)
6 changes: 6 additions & 0 deletions frontend/components/user_greetings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import streamlit as st

def user_greetings():
with st.sidebar.expander("👋 Greetings!", expanded=True):
st.write("Welcome to Studybot! This is a tool to help you revise your subjects. You can use the sidebar to navigate to the different pages. Have fun!")
st.write("If you have any feedback, please contact me on [LinkedIn](https://www.linkedin.com/in/hemanthsai7/) or [GitHub](https://github.com/HemanthSai7).")
Binary file added frontend/images/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added frontend/layouts/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions frontend/layouts/mainlayout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
import streamlit as st
from typing import Callable
from components import authors, user_greetings


def mainlayout(func: Callable):
def wrapper():
with open("layouts/st_page_layouts.json", "r", encoding="utf-8") as f:
st_page_layouts = json.load(f)

st.set_page_config(**st_page_layouts[f"{func.__name__}" if func.__name__ in st_page_layouts.keys() else "home"])
st.markdown('# :rainbow[Welcome to Studybot]🚀')
user_greetings()
authors()

func()

return wrapper
14 changes: 14 additions & 0 deletions frontend/layouts/st_page_layouts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"home": {
"page_title": "Studybot",
"layout": "wide",
"page_icon": "🏡",
"initial_sidebar_state": "expanded"
},
"bot": {
"page_title": "Chatbot",
"layout": "wide",
"page_icon": "💻",
"initial_sidebar_state": "expanded"
}
}
9 changes: 9 additions & 0 deletions frontend/pages/2_🤖_bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import streamlit as st

from layouts.mainlayout import mainlayout

@mainlayout
def bot():
st.subheader("Revise your subjects with Studybot!")

bot()
26 changes: 26 additions & 0 deletions frontend/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import streamlit as st

import requests

# from studybot import qa_chain
# st.write(qa_chain)

upload_pdf = st.file_uploader("Upload PDF", type="pdf")
if upload_pdf is not None:
files = {"file": upload_pdf}
response = requests.post(
"https://hemanthsai7-studybotapi.hf.space/api/upload", files=files
)
st.write(response)

query = st.text_input("Question", key="question")
st.write(st.session_state)

if st.button("Ask"):
# answer = qa_chain(query)
answer = requests.post(
"https://hemanthsai7-studybotapi.hf.space/api/inference",
json={"promptMessage": query},
).json()
st.write(answer)
# st.session_state["question"] = ""
74 changes: 59 additions & 15 deletions frontend/🏡_Home.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
import streamlit as st

import requests
from layouts.mainlayout import mainlayout

# from studybot import qa_chain
# st.write(qa_chain)

upload_pdf = st.file_uploader("Upload PDF", type="pdf")
if upload_pdf is not None:
files = {"file": upload_pdf}
response = requests.post("https://hemanthsai7-studybotapi.hf.space/api/upload", files=files)
st.write(response)
@mainlayout
def home():
st.subheader("Revise your subjects with Studybot!")

query=st.text_input("Question", key="question")
st.write(st.session_state)
st.markdown(
"""
<p style='text-align: justify;'>
<b>Studybot</b> is a <b>free</b> and <b>open-source</b> tool for <b>automated</b> and <b>personalized</b> learning.
It is a <b>chatbot</b> that helps you to <b>learn</b> and <b>memorize</b> new information in a <b>fun</b> and <b>easy</b> way.
Studybot is <b>free</b> and <b>open-source</b>, so you can use it <b>without any limitations</b> and <b>without any costs</b>.
You can also <b>customize</b> it to your needs and <b>contribute</b> to its development.
<b>Enjoy</b> your learning with Studybot!
</p>
""",
unsafe_allow_html=True,
)

if st.button("Ask"):
# answer = qa_chain(query)
answer = requests.post("https://hemanthsai7-studybotapi.hf.space/api/inference", json={"promptMessage": query}).json()
st.write(answer)
# st.session_state["question"] = ""
with st.expander("How does it work?", expanded=True):
st.markdown(
"""
- When you upload a document, it will be divided into smaller chunks and stored in a special type of database called a vector index that allows for semantic search and retrieval. I'm using Qdrant vector database for this purpose.
- When you ask a question, Studybot will search through the document chunks and find the most relevant ones using the vector index. Then, it will use Mistral-7B-instruct to generate a final answer.
"""
)

with st.expander("FAQs 🤔"):
st.markdown(
"""
- **What is the best way to upload a document?**<br>
The best way to upload a document is to upload a PDF file. Studybot will automatically divide it into smaller chunks. You can also upload a text file. In this case, Studybot will divide it into smaller chunks.
- **What is the best way to ask questions?**<br>
The best way to ask questions is to ask questions that are related to the document you uploaded. If you ask questions that are not related to the document you uploaded, Studybot will not be able to answer them.
- **Is my data safe?**<br>
Yes, your data is safe. Studybot does not store your documents or questions. All uploaded data is deleted after you close the browser tab since it is stored in the RAM memory. However, if you want to be sure that your data is safe, you can use the `Clear data 🧹` button to delete all uploaded data.
- **Why does it take so long to index my document?**<br>
When you upload a document, it is divided into smaller chunks and stored in a special type of database called a vector index that allows for semantic search and retrieval. It takes some time to index your document because it has to be divided into smaller chunks and stored in the vector index. However, once your document is indexed, it will be much faster to search through it.
- **Are the answers 100% accurate?**<br>
- No, the answers are not 100% accurate. Studybot uses Mistral-7B to generate answers. Mistral-7B is a powerful language model, but it sometimes makes mistakes and is prone to hallucinations. Also, Studybot uses semantic search to find the most relevant chunks and does not see the entire document, which means that it may not be able to find all the relevant information and may not be able to answer all questions (especially summary-type questions or questions that require a lot of context from the document).
- But for most of the time, Studybot is very accurate and can answer most questions. Always check with the sources to make sure that the answers are correct.
- **What is the best way to contribute to Studybot?**<br>
The best way to contribute to Studybot is to create an issue on GitHub. I will be happy to answer your questions and help you with your contributions.
""",
unsafe_allow_html=True,
)

st.divider()
# architecture heading in the middle
st.markdown("<h2 style='text-align: center; color: black;'>Studybot Architecture</h1>", unsafe_allow_html=True)
st.image("images/architecture.png")


home()

0 comments on commit e6a8680

Please sign in to comment.