Skip to content

Commit

Permalink
Code refactor (#35)
Browse files Browse the repository at this point in the history
* Code restructuring for frontend module

* Code restructuring for frontend module
  • Loading branch information
HemanthSai7 authored Oct 2, 2023
1 parent b2236e3 commit bd3ff20
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 253 deletions.
File renamed without changes.
Empty file added frontend/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions frontend/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .authors import authors
from .logout import logout
from .login import login
from .user_greetings import user_greetings
16 changes: 16 additions & 0 deletions frontend/components/authors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
import streamlit as st

def authors():
# {"Github → " "["username"]" "("url")" for username,url in author_details["socials"].items() }
# with open("frontend/contend/authors.json","r") as f:
# author_details = json.load(f)
st.sidebar.divider()
st.sidebar.info(
"""
Follow us on:
Github → [@mayureshagashe2105](https://github.com/MayureshAgashe2105)\n
Github → [@HemanthSai7](https://github.com/HemanthSai7)
"""
)
15 changes: 3 additions & 12 deletions frontend/Login.py → frontend/components/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import streamlit as st


def auth_page():
def login():

base_url = 'https://caffeinecrew-techdocs.hf.space'

Expand Down Expand Up @@ -53,18 +53,9 @@ def auth_page():

st.success("Signed up successfully")
except:
st.error("Signup Failed")
st.error("Signup Failed")


st.sidebar.divider()
st.sidebar.info(
"""
Follow us on:
Github → [@mayureshagashe2105](https://github.com/MayureshAgashe2105)\n
Github → [@HemanthSai7](https://github.com/HemanthSai7)
"""
)




Expand Down
6 changes: 6 additions & 0 deletions frontend/components/logout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import streamlit as st

def logout():
del st.session_state["access_token"]
del st.session_state["refresh_token"]
del st.session_state["username"]
12 changes: 12 additions & 0 deletions frontend/components/user_greetings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import streamlit as st
from .logout import logout

def user_greetings():
with st.sidebar.expander("🧑Account Details",expanded=True):
if 'username' not in st.session_state:
st.warning("Please Login or Signup to continue")
else:
st.info(f"Welcome, {st.session_state.username}! 😄")
if st.button("Logout 👋"):
logout()
st.rerun()
8 changes: 8 additions & 0 deletions frontend/content/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1. Python version requirement:
```bash
$ python >= 3.10
```
2. Install Techdocs via pip:
```bash
$ pip install techdocs
```
33 changes: 33 additions & 0 deletions frontend/content/working.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1. Navigate into your project directory.

```bash
$ cd <YOUR-PROJECT-DIRECTORY>
```

2. Once the installation is complete, type `techdocs` in the terminal. You should be able to see info about our CLI.

```bash
$ techdocs
```

3. If you are a `new user`, `signup` for a new account using the command below **OR** Head on to [Techdocs](https://techdocs.streamlit.app) and signup for a new account.

```bash
$ techdocs signup -u <username> -p <password> -e <email>
```

4. If you already have your `API KEY`, you can skip step 5.

5. Generate your `API key` using the command below **OR** Head on to [Techdocs](https://techdocs.streamlit.app/demo) and generate your `API KEY`.

```bash
$ techdocs apikey -u <username> -p <password>
```

6. Once you have your `API key`, you can generate the documentation using the command below.

```bash
$ techdocs generate -k <API_KEY> -u <USERNAME> -p <PASSWORD> -d <ROOT-DIRECTORY-OF-THE-PROJECT>
```

6. Wait for the `documentation` to be generated. Your `.py` files will be parsed and the documentation will be generated in the files itself. The tool will log the progress in the terminal and the file will be updated once all the functions are parsed.
Empty file added frontend/layouts/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions frontend/layouts/mainlayout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json
import streamlit as st

from typing import Callable

from components import authors, user_greetings, login

def mainlayout(func: Callable):
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 Techdocs: Where Code Meets Clarity!]🚀")

user_greetings()

if 'access_token' not in st.session_state:
st.session_state.runpage = login
else:
st.session_state.runpage = func

def load_page():
return st.session_state.runpage()
load_page()
authors()



20 changes: 20 additions & 0 deletions frontend/layouts/st_page_layouts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"home": {
"page_title": "Techdocs",
"layout": "wide",
"page_icon": "🏡",
"initial_sidebar_state": "expanded"
},
"demo": {
"page_title": "demo",
"layout": "wide",
"page_icon": "💻",
"initial_sidebar_state": "expanded"
},
"instructions": {
"page_title": "Instructions",
"layout": "wide",
"page_icon": "📝",
"initial_sidebar_state": "expanded"
}
}
83 changes: 19 additions & 64 deletions frontend/pages/Code.py → frontend/pages/2_💻_Demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,38 @@
import requests

import streamlit as st
from Login import auth_page
from layouts.mainlayout import mainlayout

st.set_page_config(
page_title="Code",
page_icon="👨‍💻",
layout="wide",
initial_sidebar_state="expanded",
)

st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!] 🚀")
@mainlayout
def demo():

def instructions():
with st.expander("📝Instructions",expanded=True):
st.info("Please note that the Streamlit app is just a demo to give the user an idea of the project. To witness the full power of Techdocs, please use the CLI. The instructions to use the CLI are listed in Usage page")
st.markdown(
"""
##### 1. Generate an `API Key` from the sidebar to get started.
##### 2. Paste the `API Key` in the field provided.
def logout():
del st.session_state["access_token"]
del st.session_state["refresh_token"]
del st.session_state["username"]
##### 3. Paste your `code function` in the input code box.
def instructions():
with st.expander("📝Instructions",expanded=True):
st.info("Please note that the Streamlit app is just a preview to give the user an idea of the project. To witness the full power of Techdocs, please use the CLI. The instructions to use the CLI are listed in Usage page")
st.markdown(
"""
##### 1. Generate an `API Key` from the sidebar to get started.
##### 4. Click on the `Generate Documentation` 🤖 button to generate the documentation.
##### 5. The `generated documentation` will be displayed in the section below.
##### 2. Paste the `API Key` in the field provided.
"""
)

##### 3. Paste your `code function` in the input code box.
base_url = 'https://caffeinecrew-techdocs.hf.space'

##### 4. Click on the `Generate Documentation` 🤖 button to generate the documentation.
##### 5. The `generated documentation` will be displayed in the section below.
"""
)


with st.sidebar:
if 'username' not in st.session_state:
with st.expander("🧑Account Details",expanded=True):
st.warning("Please Login or Signup to continue")
else:

with st.sidebar:
with st.expander("🔑 TECHDOCS-API-KEY",expanded=True):
st.warning("Generating a new API Key will invalidate the previous one from all your projects. Do you wish to continue?")
if st.button("Generate API KEY"):
with st.spinner("Generating API Key..."):
try:
base_url = "https://caffeinecrew-techdocs.hf.space"
headers={"accept":"application/json", "Authorization": f"Bearer {st.session_state.access_token}"}
response = requests.put(url=base_url + "/auth/regenerate_api_key", headers=headers, data=json.dumps({"username":st.session_state.username}))
if (response.status_code!=200):
Expand All @@ -59,20 +42,9 @@ def instructions():
st.code(response.json()["api_key"],"bash")
st.success("API Key Generated Successfully")
except Exception as e:
st.error(e)



with st.expander("🧑Account Details",expanded=True):
st.info(f"Welcome, {st.session_state.username}! 😄")
if st.button("Logout 👋"):
logout()
st.rerun()
st.error(e)


def code_page():
base_url = 'https://caffeinecrew-techdocs.hf.space'

def query_post(url, headers, data=None, params=None):
response = requests.post(url, data=data, headers=headers, params=params)
return response
Expand Down Expand Up @@ -101,20 +73,3 @@ def query_post(url, headers, data=None, params=None):
comment_placeholder.markdown(f"<pre><code>{docstr}</code></pre>", unsafe_allow_html=True)
else:
st.warning("Please enter some code.")

st.sidebar.divider()
st.sidebar.info(
"""
Follow us on:
Github → [@mayureshagashe2105](https://github.com/MayureshAgashe2105)\n
Github → [@HemanthSai7](https://github.com/HemanthSai7)
"""
)


if 'access_token' not in st.session_state:
st.session_state.runpage = auth_page
else:
st.session_state.runpage = code_page
st.session_state.runpage()
23 changes: 23 additions & 0 deletions frontend/pages/3_📝_Instructions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import streamlit as st
from PIL import Image

from layouts.mainlayout import mainlayout

@mainlayout
def instructions():
with open("content/installation.md", "r",encoding='utf-8') as f:
instructions = f.read()

with open("content/working.md", "r",encoding='utf-8') as f:
working = f.read()


st.markdown("### 📝 :rainbow[Using Techdocs via the CLI]")
st.info("Please use the CLI to generate the documentation for your project. The Streamlit app is just a demo to give the user an idea of the project.")
st.warning("To start using the CLI, please generate an API Key from the Streamlit app. You can also generate the API Key from the CLI.")

with st.expander("⚙️ Installation and setup"):
st.markdown(instructions)

with st.expander("🚀 CLI and Working", expanded=True):
st.markdown(working)
84 changes: 0 additions & 84 deletions frontend/pages/Usage.py

This file was deleted.

Loading

0 comments on commit bd3ff20

Please sign in to comment.