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
11 changes: 8 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ dependencies = [
"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)",
"bs4 (>=0.0.2,<0.0.3)",
"dotenv (>=0.9.9,<0.10.0)",
"pydantic (>=2.12.5,<3.0.0)",
"click (>=8.3.1,<9.0.0)",
]
[project.optional-dependencies]
mongo = ["pymongo (>=4.15.5,<5.0.0)"]


[tool.poetry]
Expand All @@ -30,6 +31,7 @@ packages = [
{ include = "assets/images/logo.png", from = "src" },
]

include = [{ path = "templates/**/*", format = ["sdist", "wheel"] }]

[project.scripts]
sample = "sample.cli:cli"
Expand Down
13 changes: 9 additions & 4 deletions src/sample/api/fast_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class GreetResponse(BaseModel):
message: str


@app.get("/version",tags=["Meta"])
@app.get("/version", tags=["Meta"])
def version():
return {"version": app.version}


@app.get("/", response_class=HTMLResponse,tags=["Meta"])
@app.get("/", response_class=HTMLResponse, tags=["Meta"])
async def read_root(request: Request):
return """
<html>
Expand Down Expand Up @@ -84,7 +84,7 @@ async def read_root(request: Request):
"""


@app.get("/health",tags=["Meta"])
@app.get("/health", tags=["Meta"])
def health_check():
return {"status": "ok"}

Expand All @@ -106,7 +106,12 @@ def start():
import uvicorn

print(f"🧵 {__version__}\n")
connect_db()
try:
connect_db()
except Exception:
print(
"⚠️ Could not connect to the database.Please check database configuration."
)
uvicorn.run("sample.api.fast_api:app", host="127.0.0.1", port=5000, reload=True)


Expand Down
19 changes: 13 additions & 6 deletions src/sample/cli.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
import click

from . import __version__


@click.group(invoke_without_command=True)
@click.group(
invoke_without_command=True,
help="""
Sample command-line tools.

To configure MongoDB support, install with:

pip install sample[mongo]
""",
)
@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()


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

main()


@cli.command()
@cli.command(help="Run the Sample FastAPI backend.")
def api():
"""Run the Sample FastAPI backend."""
from sample.api.fast_api import start

start()
9 changes: 8 additions & 1 deletion src/sample/features/greeting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ def greet():
st.header(APP_TITLE)

name = st.text_input("Enter your name")
connect_db()

# Try connecting, but don't crash if it fails
try:
connect_db()
except Exception:
st.warning(
"⚠️ Could not connect to the database. Please check database configuration."
)

clean_name = normalize_name(name)

Expand Down
2 changes: 1 addition & 1 deletion templates/faq.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
--bg: #2a2a2a;
--border: #3a3a3a;
--border-hover: #4a4a4a;
--summary-color: #283649;
--summary-color: #4b72a6;
--text-color: #764ba2;
}
}
Expand Down