survey / README.md
decentralizedsurvey's picture
Update README.md
106b4bf verified

A newer version of the Streamlit SDK is available: 1.56.0

Upgrade
metadata
title: Survey
emoji: 🏆
colorFrom: purple
colorTo: blue
sdk: streamlit
sdk_version: 1.50.0
app_file: app.py
pinned: false
license: mit

Deployment Steps

There are two major steps one has to follow in order to adapt and deploy our proposed solution:

  1. Deploy the underlying smart contract IPFSHashStorage.
  2. Adjust and deploy the Python code on HuggingFace.

1) Deploy IPFSHashStorage to Ethereum with Remix

This guide walks you through deploying the following Solidity contract to Ethereum (or a test network) using Remix and MetaMask. It also shows how to emit and view the Store event with an IPFS hash.

pragma solidity 0.8.18;

contract IPFSHashStorage {
    
    event Store(string data);
        
    function storeHash(string memory _IPFSHash) public {
        emit Store(_IPFSHash);
    }    
}

Prerequisites

  • A modern browser (Chrome/Brave/Firefox recommended).
  • The MetaMask wallet installed and set up.
  • Some ETH on the network you’ll deploy to:
    • For a testnet (recommended): Use Sepolia testnet with test Sepolia ETH in MetaMask.
    • For mainnet: You’ll need real ETH for gas fees.

1.1) Open Remix and create a Solidity file

  1. Go to https://remix.ethereum.org.
  2. In the File Explorers panel (left sidebar), click FileNew File.
  3. Name it IPFSHashStorage.sol.
  4. Paste the contract code from above into the file and save.

1.2) Compile the contract

  1. Click the Solidity compiler tab (the “compiler” icon) in the left sidebar.
  2. Set Compiler to 0.8.18 (matching the pragma).
  3. Click Compile And Run script.

1.3) Choose a deployment environment

Open the Deploy & run transactions tab (the “Ethereum” icon). Under Environment, pick Injected Provider - MetaMask, the follow these steps:

  1. In MetaMask, switch to your target network (e.g., Sepolia test network).
  2. Back in Remix, set Browser extension to Injected Provider - MetaMask.
  3. If a MetaMask pop-up asks you to connect, then approve it.
  4. Make sure ACCOUNT in Remix matches the address you want to use.

1.4) Deploy the contract

  1. In Contract, ensure IPFSHashStorage is selected.
  2. Click Deploy, and MetaMask will open.
  3. Confirm the transaction.
  4. Once mined, the contract will appear under Deployed Contracts with its address.

You must copy the contract address (clipboard icon), as you will need to use that value inside the Python code in the following step.

2) Adjust and deploy the Python code on HuggingFace

The easiest way of creating a new survey is to duplicate the Space at https://huggingface.co/spaces/decentralizedsurvey/survey into your own HuggingFace account and then customize the file app.py.

2.1) Duplicate the Space

  1. Open: https://huggingface.co/spaces/decentralizedsurvey/survey
  2. In the top-right of the Space page, click the ⋯ (three dots) menu → Duplicate this Space.
  3. In the dialog:
    • Owner: pick your username or an organization you can write to.
    • Space name: choose a new name (e.g., my-survey).
    • Visibility: Public or Private.
  4. Next, you have to provide four secrets that are not publicly visible, but these values are used by the survey code. Note that we use Infura as the API provider that facilitates our access to Ethereum and IPFS. Other providers can certainly be used, such as Pinata.
    • infura: Infura's Ethereum endpoint
    • password: Infura's username
    • username: Infura's username
    • pk: The private key of an Ethereum wallet, such as MetaMask. This will be used to sign and pay for the data stored on Ethereum
  5. Click Duplicate Space. After a few seconds, you’ll be redirected to your copy.

2.2) Confirm files and SDK

  1. Go to your duplicated Space.
  2. Open the Files tab; you should see (at least):
    • app.py — the Streamlit entry point.
    • requirements.txt — Python dependencies.

2.3) Edit app.py in the browser

  1. In Files, click app.py.
  2. Click the Edit (pencil) button.
  3. Make your changes (see examples below).
  4. Enter a short commit message and click Commit changes.

Your Space will rebuild automatically and then transition to Running when ready.

Suggestion for customization:

  • App title & page settings
    Look for st.set_page_config(...) and st.title(...) at the top to change the browser title, page icon, and the on-page title.

  • Smart contract address
    Make sure you change the address of the smart contract. The new value is what you obtained after finishing the previous major step.

  • Questions & options
    The survey uses widgets like st.radio, st.selectbox, st.text_input, etc. You can:

    • Change question text.
    • Modify option lists (e.g., age ranges, yes/no, periods).
    • Add validation (e.g., require an answer before proceeding).
  • Multi-page flow
    The app tracks a current_page (often via st.session_state). Pages are commonly implemented as if/elif sections by page number. To add a new page:

    1. Duplicate a page block:
      if st.session_state["current_page"] == 3:
          st.header("New page")
          # add widgets here
          if st.button("Next"):
              st.session_state["current_page"] += 1
      
    2. Update any constants such as total_number_pages if used.
    3. Ensure Back/Next buttons move between pages as expected.
  • Media and styles

    • Replace any st.video("https://...") URL to change the intro video.
    • Use st.markdown("<style>...</style>", unsafe_allow_html=True) for small CSS tweaks.
    • Add images via st.image("path-or-url").

Next steps

Although the preceding steps target online surveys, the same architecture generalizes readily to other data-collection modalities. For example, with some adjustments to the Python front end, researchers can instrument semi-structured interviews or web-based behavioral experiments, capture rich response streams (audio, text, interaction logs), and serialize the results for content-addressable storage on IPFS, thereby preserving provenance and facilitating reproducible analysis across studies and domains.