HemanthSai7 commited on
Commit
83e703d
β€’
1 Parent(s): 03c48e7

Streamlit app

Browse files
frontend/components/__init__.py CHANGED
@@ -1,2 +1,3 @@
1
  from .authors import *
2
- from .user_greetings import *
 
 
1
  from .authors import *
2
+ from .user_greetings import *
3
+ from .logo import add_logo
frontend/components/logo.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import re
3
+ import base64
4
+ import validators
5
+ from pathlib import Path
6
+
7
+
8
+ def add_logo(logo_url: str, height: int = 100, svg=False):
9
+ if svg:
10
+ svg_logo = read_svg(logo_url)
11
+ b64 = base64.b64encode(svg_logo.encode("utf-8")).decode("utf-8")
12
+ logo = f'url("data:image/svg+xml;base64,{b64}")'
13
+ elif validators.url(logo_url):
14
+ logo = f"url({logo_url})"
15
+ else:
16
+ logo = f'url("data:image/png;base64,{base64.b64encode(Path(logo_url).read_bytes()).decode()}")'
17
+ st.markdown(
18
+ f"""
19
+ <style>
20
+ [data-testid="stSidebarNav"] {{
21
+ background-image: {logo};
22
+ background-repeat: no-repeat;
23
+ background-position: center top; /* Center the logo at the top */
24
+ background-size: auto {height}px; /* Set the logo height */
25
+ }}
26
+ </style>
27
+ """,
28
+ unsafe_allow_html=True,
29
+ )
30
+
31
+
32
+ def read_svg(path_svg):
33
+ try:
34
+ with open(path_svg, "r") as file:
35
+ svg_logo = file.read().splitlines()
36
+ _maped_list = map(str, svg_logo)
37
+ svg_logo = "".join(_maped_list)
38
+ temp_svg_logo = re.findall("<svg.*</svg>", svg_logo, flags=re.IGNORECASE)
39
+ svg_logo = temp_svg_logo[0]
40
+ except:
41
+ svg_logo = '<svg xmlns="http://www.w3.org/2000/svg" width="150px" height="1px" viewBox="0 0 150 1"></svg>'
42
+ return svg_logo
43
+
44
+
45
+ def render_svg(svg):
46
+ b64 = base64.b64encode(svg.encode("utf-8")).decode("utf-8")
47
+ html = (
48
+ r"""
49
+ <div align="center">
50
+ <img src="data:image/svg+xml;base64,%s" alt="Techdocs Logo" style="width: 60em;"/>
51
+ </div>
52
+ """
53
+ % b64
54
+ )
55
+ st.markdown(html, unsafe_allow_html=True)
frontend/components/user_greetings.py CHANGED
@@ -1,6 +1,11 @@
1
  import streamlit as st
2
 
 
3
  def user_greetings():
4
  with st.sidebar.expander("πŸ‘‹ Greetings!", expanded=True):
5
- 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!")
6
- st.write("If you have any feedback, please contact me on [LinkedIn](https://www.linkedin.com/in/hemanthsai7/) or [GitHub](https://github.com/HemanthSai7).")
 
 
 
 
 
1
  import streamlit as st
2
 
3
+
4
  def user_greetings():
5
  with st.sidebar.expander("πŸ‘‹ Greetings!", expanded=True):
6
+ st.write(
7
+ "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!"
8
+ )
9
+ st.write(
10
+ "If you have any feedback, please contact me on [:orange[LinkedIn]](https://www.linkedin.com/in/hemanthsai7/) or [:orange[GitHub]](https://github.com/HemanthSai7)."
11
+ )
frontend/images/studybotlogo.svg ADDED
frontend/layouts/mainlayout.py CHANGED
@@ -1,16 +1,23 @@
1
  import json
2
  import streamlit as st
3
  from typing import Callable
4
- from components import authors, user_greetings
5
 
6
 
7
  def mainlayout(func: Callable):
8
  def wrapper():
9
- with open("frontend/layouts/st_page_layouts.json", "r", encoding="utf-8") as f:
10
  st_page_layouts = json.load(f)
11
 
12
- st.set_page_config(**st_page_layouts[f"{func.__name__}" if func.__name__ in st_page_layouts.keys() else "home"])
13
- st.markdown('# :rainbow[Welcome to Studybot]πŸš€')
 
 
 
 
 
 
 
14
  user_greetings()
15
  authors()
16
 
 
1
  import json
2
  import streamlit as st
3
  from typing import Callable
4
+ from components import authors, user_greetings, add_logo
5
 
6
 
7
  def mainlayout(func: Callable):
8
  def wrapper():
9
+ with open("layouts/st_page_layouts.json", "r", encoding="utf-8") as f:
10
  st_page_layouts = json.load(f)
11
 
12
+ st.set_page_config(
13
+ **st_page_layouts[
14
+ f"{func.__name__}"
15
+ if func.__name__ in st_page_layouts.keys()
16
+ else "home"
17
+ ]
18
+ )
19
+ add_logo("images/studybotlogo.svg", svg=True)
20
+ st.markdown("# Studybot πŸ“š")
21
  user_greetings()
22
  authors()
23
 
frontend/🏑_Home.py CHANGED
@@ -20,14 +20,15 @@ def home():
20
  unsafe_allow_html=True,
21
  )
22
 
23
- with st.expander("How does it work?", expanded=True):
24
- st.markdown(
25
  """
26
  - 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.
27
 
28
  - 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.
29
 
30
- """
 
31
  )
32
 
33
  with st.expander("FAQs πŸ€”"):
@@ -55,11 +56,14 @@ def home():
55
  """,
56
  unsafe_allow_html=True,
57
  )
58
-
59
  st.divider()
60
  # architecture heading in the middle
61
- st.markdown("<h2 style='text-align: center; color: black;'>Studybot Architecture</h1>", unsafe_allow_html=True)
62
- st.image("frontend/images/architecture.png")
 
 
 
63
 
64
 
65
  home()
 
20
  unsafe_allow_html=True,
21
  )
22
 
23
+ with st.expander("How does it work? βš™οΈ", expanded=True):
24
+ st.info(
25
  """
26
  - 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.
27
 
28
  - 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.
29
 
30
+ """,
31
+ icon="ℹ️",
32
  )
33
 
34
  with st.expander("FAQs πŸ€”"):
 
56
  """,
57
  unsafe_allow_html=True,
58
  )
59
+
60
  st.divider()
61
  # architecture heading in the middle
62
+ st.markdown(
63
+ "<h2 style='text-align: center; color: black;'>Studybot Architecture</h1>",
64
+ unsafe_allow_html=True,
65
+ )
66
+ st.image("images/architecture.png")
67
 
68
 
69
  home()