Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script for turning any nada program and test into a streamlit app #36

Merged
merged 8 commits into from
Oct 10, 2024

Conversation

oceans404
Copy link
Member

Deploying Streamlit Apps with the generate-streamlit-app script

To deploy Streamlit apps, they need to be written and committed to a public Github repo.

How to add a new Streamlit App

0. Create a streamlit secrets file and add your nilchain private key within .streamlit/secrets.toml

cp .streamlit/secrets.toml.example .streamlit/secrets.toml

1. Run the script to generate a new streamlit app for your program

From the root folder of this repo, run the generate-streamlit-app script:

python3 generate-streamlit-app.py

2. Follow the prompts to

  • Select an existing program (from the src/ directory)
  • Select an existing yaml test file for your program (from the tests/ directory)

This will generate a Streamlit app file: streamlitdemo_apps/app[your_program_name].py. The script will run the Streamlit app locally with this command

streamlit run streamlit_demo_apps/app_[your_program_name].py`

3. Test your Streamlit app locally

View the app in your browser to make sure everything works as expected.

4. Deploy your app

Add and commit your new streamlit app code to your forked Github repo. (Code must be connected to a remote, open source GitHub repository to deploy a Streamlit app.)

git add .
git commit -m "my new streamlit nillion app"
git push origin main

Once you've committed the open source code, you can click the "deploy" button within your local streamlit app. Sign in with Github and select the "Deploy Now" on Streamlit Community Cloud option to deploy the app for free.

Deploy an app settings

Set the main file path to your new app streamlit_demo_apps/app_[your_program_name].py

Go to "Advanced settings" and in Secrets, copy in the contents of your .streamlit/secrets.toml file. At a minimum, make sure to add your secret private key:

nilchain_private_key = "YOUR_FUNDED_PRIVATE_KEY"

Save and click "Deploy" to deploy your testnet Streamlit app!

streamlit_app.py Show resolved Hide resolved
streamlit_demo_apps/README.md Outdated Show resolved Hide resolved
streamlit_demo_apps/README.md Outdated Show resolved Hide resolved
@@ -1,15 +1,19 @@
# Deploying Streamlit Apps

To deploy Streamlit apps, they need to be written and committed to a public GitHub repository.
This guide will show you how to quickly spin up a Nillion Testnet connected, live Streamlit app from our template using the simple generate-streamlit-app script. Once your app is ready, you can easily deploy it by pushing it to a public GitHub repo. Just follow these steps to get started:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a Nillion Testnet connected, live Streamlit app f

this reads a bit odd - but might be me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Follow the steps to deploy a live Streamlit app for your Nada program. The app will connect to the Nillion Testnet to store your Nada program, store secret inputs (or use computation time secrets), and run blind computation"

streamlit_demo_apps/README.md Outdated Show resolved Hide resolved

### 4. Commit your code to GitHub

Add and commit your new streamlit app code to your forked Github repo. (Code must be connected to a remote, open source GitHub repository to deploy a Streamlit app.)
Copy link
Contributor

@crypblizz8 crypblizz8 Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forking repo was not mentioned in the main repo README / here. Should we explicitly mention this higher in case?

With my test - i cloned repo instead of forking it 😅

Copy link
Contributor

@crypblizz8 crypblizz8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - very simple and easy process to follow.

Took 2-3mins for me 👍

streamlit_app.py Outdated
@@ -156,32 +189,15 @@ def main(nada_test_file_name=None, path_nada_bin=None, path_nada_json=None):
st.code(program_code, language='python')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
st.code(program_code, language='python')
with st.expander(f"Nada Program: {program_name}"):
st.code(program_code, language='python')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovered you can make this collapsible. Makes it easier to go straight to the inputs instead of looking at the code. just a suggestion.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great point! will add this

@oceans404 oceans404 merged commit 8471b2f into main Oct 10, 2024
1 check failed
@oceans404 oceans404 deleted the feat/questionary branch October 10, 2024 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants