Skip to content

Commit

Permalink
🤖 Add streamlit app to test ui feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
eli64s committed Aug 1, 2023
1 parent 5a451f0 commit 4c1f88c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ All notable changes to this project will be documented in this file.

## [v0.0.5] - *2023-07-31*

### Added
### Added

- Add [.dockerignore](./.dockerignore) file to exclude unnecessary files from the Docker image.

### Fixed
### 🛠️ Fixed

- Missing html closing tags in README tables were causing the GitHub pages site to render incorrectly.
- Added closing tags to fix the issue.
- Additionally, restructured a few sections of the README.

### Security
### 🛡️ Security

- Refactor Dockerfile to adhere to best practices.
- *Package Installation and Cleanup:* Clean up cache after installing packages with apt-get to reduce the image size.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,10 @@ bash scripts/test.sh
## 🛠 Future Development

- [X] Add additional language support for populating the *installation*, *usage*, and *test* README sections.
- [X] Upload the *readme-ai* CLI tool to PyPI under the module name [readmeai](https://pypi.org/project/readmeai/).
- [X] Publish the *readme-ai* CLI app to PyPI [readmeai](https://pypi.org/project/readmeai/).
- [ ] Create user interface and serve the *readme-ai* app via streamlit.
- [ ] Design and implement a variety of README template formats for different use-cases.
- [ ] Add support for writing the README in any language (i.e. CN, ES, FR, JA, KO, RU).
- [ ] Create UI with [Textual](https://github.com/Textualize/textual) or another framework to improve user experience.

---

Expand Down
92 changes: 92 additions & 0 deletions readmeai/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Streamlit app for README-AI."""

import logger
import subprocess
import time

import streamlit as st

from readmeai import logger

LOGGER = logger.Logger(__name__)


def run_cli(openai_api_key, output_path, repository_path):
"""Run the README-AI CLI."""
if not output_path or not repository_path:
st.error("Output path and repository path must be provided.")
return

command = [
"readmeai",
"-k",
openai_api_key,
"-o",
output_path,
"-r",
repository_path,
]

st.session_state.generating = True

with st.spinner("Generating README..."):
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
time.sleep(1)

if result.returncode == 0:
st.success("README-AI executed successfully!")
try:
with open(output_path, "r", encoding="utf-8") as readme_file:
readme_content = readme_file.read()
st.subheader("Generated README.md:")
st.code(readme_content, language="markdown")
st.download_button(
"Download README.md",
data=readme_content,
file_name="README.md",
)
except FileNotFoundError:
LOGGER.error("README.md file not found.")
st.warning(
"README.md file not found. Please check your configuration."
)
else:
LOGGER.error(f"Error running the README-AI: {result.stderr}")
st.error(f"Error running the README-AI: {result.stderr}")
except subprocess.CalledProcessError as e:
LOGGER.error(f"Error running the README-AI: {e}")
st.error(f"Error running the README-AI: {e}")
finally:
st.session_state.generating = False


def main():
"""Streamlit app entrypoint."""
st.title("🤖 README-AI")
st.write(
"Enter your repository details and click run...we'll generate a README.md for you!"
)

openai_api_key = st.text_input("OpenAI API Key:", type="password")

output_path = st.text_input("Output file path:")
repository_path = st.text_input("Repository url or path:")

if st.button(
"Run",
key="run_button",
on_click=run_cli,
args=(openai_api_key, output_path, repository_path),
):
if "generating" not in st.session_state or not st.session_state.generating:
st.session_state.generating = False
with st.empty():
progress_bar = st.progress(0)
for i in range(1, 101):
time.sleep(0.02)
progress_bar.progress(i)


if __name__ == "__main__":
main()

0 comments on commit 4c1f88c

Please sign in to comment.