Spaces:
Runtime error
Runtime error
Hemanth Sai Garladinne commited on
Commit ยท
fbb7c49
1
Parent(s): e3122d2
Code refactor (#35)
Browse files* Code restructuring for frontend module
* Code restructuring for frontend module
Files changed (16)
- frontend/.streamlit/config.toml โ .streamlit/config.tomlRenamed
- frontend/__init__.pyAdded
- frontend/components/__init__.pyAdded+4
- frontend/components/authors.pyAdded+16
- frontend/Login.py โ frontend/components/login.pyRenamed+3-12
- frontend/components/logout.pyAdded+6
- frontend/components/user_greetings.pyAdded+12
- frontend/content/installation.mdAdded+8
- frontend/content/working.mdAdded+33
- frontend/layouts/__init__.pyAdded
- frontend/layouts/mainlayout.pyAdded+27
- frontend/layouts/st_page_layouts.jsonAdded+20
- frontend/pages/Code.py โ frontend/pages/2_๐ป_Demo.pyRenamed+19-64
- frontend/pages/3_๐_Instructions.pyAdded+23
- frontend/pages/Usage.pyDeleted-84
- frontend/๐ก_Home.py+11-93
1234from .authors import authorsfrom .logout import logoutfrom .login import loginfrom .user_greetings import user_greetings12345678910111213141516import jsonimport 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) """ )3 unmodified lines4567891042 unmodified lines5354555657585960616263646566676869703 unmodified linesimport streamlit as stdef auth_page():base_url = 'https://caffeinecrew-techdocs.hf.space'42 unmodified linesst.success("Signed up successfully")except:st.error("Signup Failed")st.sidebar.divider()st.sidebar.info("""Follow us on:Github โ [@mayureshagashe2105](https://github.com/MayureshAgashe2105)\nGithub โ [@HemanthSai7](https://github.com/HemanthSai7)""")3 unmodified lines4567891042 unmodified lines5354555657585960613 unmodified linesimport streamlit as stdef login():base_url = 'https://caffeinecrew-techdocs.hf.space'42 unmodified linesst.success("Signed up successfully")except:st.error("Signup Failed")
123456import streamlit as st
def logout(): del st.session_state["access_token"] del st.session_state["refresh_token"] del st.session_state["username"]123456789101112import streamlit as stfrom .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()123456781. Python version requirement:```bash$ python >= 3.10```2. Install Techdocs via pip:```bash$ pip install techdocs```1234567891011121314151617181920212223242526272829303132331. 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.123456789101112131415161718192021222324252627import jsonimport 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()
1234567891011121314151617181920{ "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" }}1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455562 unmodified lines596061626364656667686970717273747576777822 unmodified lines1011021031041051061071081091101111121131141151161171181191201 unmodified lineimport requestsimport streamlit as stfrom Login import auth_pagest.set_page_config(page_title="Code",page_icon="๐จโ๐ป",layout="wide",initial_sidebar_state="expanded",)st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!] ๐")def logout():del st.session_state["access_token"]del st.session_state["refresh_token"]del st.session_state["username"]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.##### 2. Paste the `API Key` in the field provided.##### 3. Paste your `code function` in the input code box.##### 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.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):2 unmodified linesst.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()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 response22 unmodified linescomment_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)\nGithub โ [@HemanthSai7](https://github.com/HemanthSai7)""")if 'access_token' not in st.session_state:st.session_state.runpage = auth_pageelse:st.session_state.runpage = code_pagest.session_state.runpage()1 unmodified line234567891011121314151617181920212223242526272829303132333435363738392 unmodified lines42434445464748495022 unmodified lines7374751 unmodified lineimport requestsimport streamlit as stfrom layouts.mainlayout import mainlayout@mainlayoutdef 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.##### 3. Paste your `code function` in the input code box.##### 4. Click on the `Generate Documentation` ๐ค button to generate the documentation.##### 5. The `generated documentation` will be displayed in the section below.""")base_url = 'https://caffeinecrew-techdocs.hf.space'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: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):2 unmodified linesst.code(response.json()["api_key"],"bash")st.success("API Key Generated Successfully")except Exception as e:st.error(e)def query_post(url, headers, data=None, params=None):response = requests.post(url, data=data, headers=headers, params=params)return response22 unmodified linescomment_placeholder.markdown(f"<pre><code>{docstr}</code></pre>", unsafe_allow_html=True)else:st.warning("Please enter some code.")
1234567891011121314151617181920212223import streamlit as stfrom PIL import Image
from layouts.mainlayout import mainlayout
@mainlayoutdef 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) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import streamlit as stfrom Login import auth_pagefrom PIL import Image
st.set_page_config( page_title="Usage", layout="wide", page_icon="๐", initial_sidebar_state="expanded",)
st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!]๐")
def logout(): del st.session_state["access_token"] del st.session_state["refresh_token"] del st.session_state["username"]
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()
def usage(): st.markdown("### :rainbow[How to use Techdocs?]")
col1,col2 = st.columns(2,gap="small")
with col1:
img = Image.open("frontend/images/image.png") st.image(img)
st.caption("Boat sailing in the sea")
with col2: intro_text=""" Now that you've arrived at this digital crossroads, you're most likely eager to dive into the world of Techdocs. Great choice! In today's fast-paced tech landscape, having well-structured and easily accessible documentation is like having a treasure map to navigate the vast ocean of code. You are probably wondering how to use Techdocs. """
text=""" But you might be wondering: "How do I embark on this documentation journey with Techdocs?" Fear not, because we're about to chart a course through the fascinating world of Techdocs, where clarity, efficiency, and ease-of-use are the guiding stars. """ st.write(f'<p style="font-size:22px; color:#9c9d9f ">{intro_text}</p>', unsafe_allow_html=True) st.write(f'<p style="color:#9c9d9f; font-size:22px">{text}</p>', unsafe_allow_html=True)
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 preview 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",expanded=True): st.write("1. Create a virtual environment. We recommend using conda but you can python's venv as well:"); st.code("conda create -n techdocs python=3.11","python") st.write("2. Install Techdocs via pip:"); st.code("pip install techdocs","python") st.write("3. CD into your project directory.") st.code("CD <YOUR-PROJECT-DIRECTORY>","bash")
with st.expander("๐ CLI and Working", expanded=True): st.write("1. Once the installation is complete, type **techdocs** in the terminal. You should be able to see info about our CLI.") st.write("2. You can login into our Techdocs app using the CLI or create an account if you don't have one. To signup, type the following command in the terminal:") st.code("techdocs signup -u <username> -p <password> -e <email>", "bash") st.write("3. Generate an API Key from the Code page and paste it in the command below.") st.code("techdocs generate -k <API_KEY> -u <USERNAME> -p <PASSWORD> -d <ROOT-DIRECTORY-OF-THE-PROJECT>","bash") st.write("4. Wait for the documentation to be generated. You can view the status of the documentation generation in the CLI.")
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_pageelse: st.session_state.runpage = usagest.session_state.runpage() 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106import streamlit as stfrom Login import auth_pageimport base64st.set_page_config(page_title="Techdocs",layout="wide",page_icon="๐ก",initial_sidebar_state="expanded")@st.cache_datadef get_base64_bin_file(bin_file):with open(bin_file, 'rb') as f:data = f.read()return base64.b64encode(data).decode()st.markdown("## :rainbow[Welcome to Techdocs: Where Code Meets Clarity!]๐")def logout():del st.session_state["access_token"]del st.session_state["refresh_token"]del st.session_state["username"]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()def home_page():def set_page_background(png_file):bin_str = get_base64_bin_file(png_file)page_bg_img = f'''<style>.stApp {{background-image: url("data:image/jpg;base64,{bin_str}");background-size: cover;background-repeat: no-repeat;background-attachment: scroll;}}</style>'''st.markdown(page_bg_img, unsafe_allow_html=True)# set_page_background("../assets/bg.jpg")st.markdown("""##### Unleash the documentation dynamo that is **Techdocs**! Say goodbye to the documentation drudgery that haunts coders' dreams and embrace the effortless power of AI-driven documentation. With **Techdocs**, harness the genius of LLama2, the magic of WizardCoderLM, the versatility of Huggingface Transformers, and the precision of Langchain and Clarifai.## :rainbow[How Does Techdocs Work Its Magic?] ๐ฎ##### Just feed your code into **Techdocs**, and like a seasoned wizard, it'll conjure up beautifully detailed documentation in an instant. Your code will transform into a masterpiece of clarity, complete with insightful comments, vivid descriptions, crystal-clear parameters, return values, and real-world examples.""")with st.expander("What Can Techdocs Do for You? ๐",expanded=True):st.markdown("""- ##### Boost your code quality effortlessly ๐.- ##### Share your brilliance with the world in a snap ๐.- ##### Effortlessly generate documentation for your code ๐ค.- ##### Include comments, descriptions, parameters, return values, and real-life examples ๐.- ##### Elevate your code's readability, maintainability, and quality ๐.""")st.markdown("""##### **Techdocs** is your code's trusty companion, helping you document with ease so you can focus on what you do best: coding!. **Techdocs** is your secret weapon for leveling up your code game. Whether you're a seasoned developer or just starting your coding journey, Techdocs has got your back. Get ready to unlock the future of code documentation today! ๐""")st.markdown("""## :rainbow[Ready to use Techdocs?]##### Head over to the `Usage page` to get started!๐""")st.sidebar.divider()st.sidebar.info("""Follow us on:Github โ [@mayureshagashe2105](https://github.com/MayureshAgashe2105)\nGithub โ [@HemanthSai7](https://github.com/HemanthSai7)""")if 'access_token' not in st.session_state:st.session_state.runpage = auth_pageelse:st.session_state.runpage = home_pagest.session_state.runpage()123456789101112131415161718192021222324import streamlit as stfrom layouts.mainlayout import mainlayout@mainlayoutdef home_page():st.markdown("""##### Unleash the documentation dynamo that is **Techdocs**! Say goodbye to the documentation drudgery that haunts coders' dreams and embrace the effortless power of AI-driven documentation. With **Techdocs**, harness the genius of LLama2 ๐ฆ, the magic of WizardCoderLM ๐งโโ๏ธ, the versatility of Huggingface Transformers ๐ค, and the precision of Langchain ๐ฆ and Clarifai ๐ค.""")with st.expander("What Can Techdocs Do for You? ๐",expanded=True):st.markdown("""- Boost your code quality effortlessly ๐.- Effortlessly generate documentation for your code ๐ค.- Include comments, descriptions, parameters, return values, and real-life examples ๐.- Elevate your code's readability, maintainability, and quality ๐.#""")
frontend/.streamlit/config.toml โ .streamlit/config.tomlRenamed
frontend/__init__.pyAdded
frontend/components/__init__.pyAdded+4
frontend/components/authors.pyAdded+16
frontend/Login.py โ frontend/components/login.pyRenamed+3-12
frontend/components/logout.pyAdded+6
frontend/components/user_greetings.pyAdded+12
frontend/content/installation.mdAdded+8
frontend/content/working.mdAdded+33
frontend/layouts/__init__.pyAdded
frontend/layouts/mainlayout.pyAdded+27
frontend/layouts/st_page_layouts.jsonAdded+20
frontend/pages/Code.py โ frontend/pages/2_๐ป_Demo.pyRenamed+19-64
frontend/pages/3_๐_Instructions.pyAdded+23
frontend/pages/Usage.pyDeleted-84
frontend/๐ก_Home.py+11-93