Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Fabric Generator and Search Utility

A Streamlit template for Recursive Zero repository
A Sample template for Recursive Zero repository

## Installation Guide

## Prerequisites

- Python ≥ 3.11
- Poetry ≥ 2.2.1
- Streamlit ≥ 1.49.1

## Getting Started

Expand All @@ -34,7 +33,6 @@ Ensure below files are configured (create if not exist) properly to run the proj

- `.env.local`,
- `.env`, and
- `.streamlit/secrets.toml`

## Install Dependencies

Expand All @@ -51,7 +49,7 @@ poetry install

## How to Run

## Run Streamlit App
## Run Sample App

```bash
poetry run sample dev
Expand Down Expand Up @@ -120,7 +118,7 @@ pip install sample

## CLI Shortcuts

`sample dev` → Launch Streamlit UI
`sample dev` → Launch Sample UI

`sample api` → Launch FastAPI

Expand Down
2 changes: 1 addition & 1 deletion docs/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pip show sample

## CLI Shortcuts

`sample dev` → Launch Streamlit UI
`sample dev` → Launch frontend

`sample api` → Launch FastAPI

Expand Down
5 changes: 2 additions & 3 deletions docs/CLOUD.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Cloud Deployment

- Install python v 3.12, streamlit and poetry using pip
- Install python v 3.12,poetry using pip

```sh
sudo apt install python3-pip python3-venv
pip install streamlit
curl -sSL https://install.python-poetry.org | python3.12 -
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
# install additional required packages
Expand All @@ -27,7 +26,7 @@ poetry env info
```

- copy sample repo in a folder
- copy `.env` and `.streamlit/config.toml` to that folder
- copy `.env` to that folder
- go to folder and install package dependencies

```sh
Expand Down
2 changes: 1 addition & 1 deletion docs/DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Deployment Guide

## Export Requirements for Streamlit
## Export Requirements

```bash
poetry export -f requirements.txt --without-hashes --output requirements.txt \
Expand Down
3 changes: 1 addition & 2 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

- Python ≥ 3.11
- Poetry ≥ 2.2.1
- Streamlit ≥ 1.49.1

## Getting Started

Expand All @@ -26,7 +25,7 @@ pip install poetry>=1.5.0
poetry config virtualenvs.path /your/desired/path
```

Ensure `.env.local`, `.env`, and `.streamlit/secrets.toml` are configured with appropriate keys.
Ensure `.env.local`, `.env` are configured with appropriate keys.

## Install Dependencies

Expand Down
2 changes: 1 addition & 1 deletion docs/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# How to Run

## Run Streamlit App
## Run Sample app

```bash
poetry run sample dev
Expand Down
2 changes: 1 addition & 1 deletion docs/setup-for-osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ poetry run ruff check
poetry show --tree
```

3. **Run the Streamlit application:**
3. **Run the Sample app:**

```sh
poetry run sample dev
Expand Down
930 changes: 122 additions & 808 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[project]
name = "sample"
version = "1.0.0"
description = "A python template for fastapi and streamlit projects."
description = "A python template for fastapi and projects."
authors = [{ name = "sample", email = "[email protected]" }]
license = "MIT"
readme = "README.md"
requires-python = ">=3.10,<3.13"
keywords = ["python", "fastapi", "streamlit"]
keywords = ["python", "fastapi"]
classifiers = [
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Image Recognition",
]
dependencies = [
"fastapi (>=0.121.1,<0.122.0)",
"streamlit>=1.49.0",
"python-box (>=7.3.2,<8.0.0)",
"uvicorn (>=0.40.0,<0.41.0)",
"pymongo (>=4.15.5,<5.0.0)",
"dotenv (>=0.9.9,<0.10.0)",
]


Expand Down
18 changes: 0 additions & 18 deletions src/features/greeting.py

This file was deleted.

89 changes: 19 additions & 70 deletions src/sample/__main__.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,35 @@
# sample/__main__.py

from . import __version__
import sys
import logging
import subprocess
from pathlib import Path
import click

logging.basicConfig(level=logging.INFO)


@click.group(invoke_without_command=True)
@click.option("--version", is_flag=True, help="Show the Sample version and exit.")
@click.pass_context
def cli(ctx, version):
"""Sample command-line tools."""
if version:
click.echo(__version__)
ctx.exit()

from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
import os

@cli.command()
def dev():
"""Run the Sample Streamlit app."""
main()


@cli.command()
def api():
"""Run the Sample FastAPI backend."""
from api.fast_api import start
from utils.constants import PORT
from . import __version__

start()


def main():
"""
Entrypoint for the Streamlit 'dev' app.
"""
print("🏷️ Sample version:", __version__)
logging.info("Starting sample dev script...")

# Paths
Sample_dir = Path(__file__).resolve().parent
dev_root = Sample_dir.parent # src/
wheel_root = Sample_dir.parent # same in wheel
logging.info("Starting static HTML server...")

# Add correct root to sys.path
if "site-packages" in str(Sample_dir): # running from wheel
if str(wheel_root) not in sys.path:
sys.path.append(str(wheel_root))
logging.info(f"Added wheel root to sys.path: {wheel_root}")
else: # dev mode
if str(dev_root) not in sys.path:
sys.path.append(str(dev_root))
logging.info(f"Added dev src root to sys.path: {dev_root}")
sample_dir = Path(__file__).resolve().parent.parent

# Locate streamlit_app.py
streamlit_app_path = Sample_dir / "streamlit_app.py"
logging.info(f"Streamlit app path: {streamlit_app_path}")
if "site-packages" in str(sample_dir):
root = sample_dir
logging.info("Running from wheel")
else:
root = sample_dir.parent
logging.info("Running in dev mode")

if not streamlit_app_path.exists():
logging.error(f"Streamlit app not found at: {streamlit_app_path}")
return
logging.info(f"Serving from root: {root}")

# Run Streamlit app
python_path = sys.executable
logging.info(f"Using Python executable: {python_path}")
os.chdir(root)

subprocess.run(
[
python_path,
"-m",
"streamlit",
"run",
str(streamlit_app_path.resolve()),
"--server.port",
"8501",
],
check=True,
)
with TCPServer(("", PORT), SimpleHTTPRequestHandler) as httpd:
print(f"🌐 Open http://localhost:{PORT}/templates/index.html")
httpd.serve_forever()


if __name__ == "__main__":
cli()
main()
2 changes: 1 addition & 1 deletion src/sample/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def cli(ctx, version):

@cli.command()
def dev():
"""Run the Sample Streamlit app."""
"""Run the Sample app."""
from sample.__main__ import main

main()
Expand Down
60 changes: 0 additions & 60 deletions src/sample/streamlit_app.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
from db.connection import mongo_client

if mongo_client:
print("MongoDB connected successfully.")
Loading