simple website made
This commit is contained in:
parent
880e7850c1
commit
c089006386
8 changed files with 210 additions and 0 deletions
12
frontend/Dockerfile
Normal file
12
frontend/Dockerfile
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8501
|
||||
|
||||
CMD ["streamlit", "run", "app.py", "--server.address", "0.0.0.0", "--server.port", "8501", "--server.headless", "true"]
|
||||
58
frontend/app.py
Normal file
58
frontend/app.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import streamlit as st
|
||||
import requests
|
||||
import os
|
||||
|
||||
BACKEND_URL = os.environ.get("BACKEND_URL", "http://localhost:8000")
|
||||
|
||||
st.set_page_config(page_title="Notes", page_icon="📝")
|
||||
st.title("📝 Notes")
|
||||
|
||||
# Add note
|
||||
with st.form("add_note", clear_on_submit=True):
|
||||
st.subheader("New Note")
|
||||
title = st.text_input("Title")
|
||||
content = st.text_area("Content", height=100)
|
||||
submitted = st.form_submit_button("Add Note", use_container_width=True)
|
||||
|
||||
if submitted:
|
||||
if not title.strip():
|
||||
st.error("Title is required.")
|
||||
else:
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{BACKEND_URL}/notes",
|
||||
json={"title": title, "content": content},
|
||||
timeout=5,
|
||||
)
|
||||
if r.status_code == 200:
|
||||
st.success("Note added!")
|
||||
st.rerun()
|
||||
else:
|
||||
st.error(f"Backend error: {r.text}")
|
||||
except Exception as e:
|
||||
st.error(f"Could not reach backend: {e}")
|
||||
|
||||
st.divider()
|
||||
st.subheader("All Notes")
|
||||
|
||||
try:
|
||||
r = requests.get(f"{BACKEND_URL}/notes", timeout=5)
|
||||
notes = r.json()
|
||||
|
||||
if not notes:
|
||||
st.info("No notes yet. Add one above.")
|
||||
else:
|
||||
for note in notes:
|
||||
with st.container(border=True):
|
||||
col1, col2 = st.columns([5, 1])
|
||||
with col1:
|
||||
st.markdown(f"**{note['title']}**")
|
||||
if note.get("content"):
|
||||
st.write(note["content"])
|
||||
st.caption(note["created_at"])
|
||||
with col2:
|
||||
if st.button("Delete", key=f"del_{note['id']}"):
|
||||
requests.delete(f"{BACKEND_URL}/notes/{note['id']}", timeout=5)
|
||||
st.rerun()
|
||||
except Exception as e:
|
||||
st.error(f"Could not reach backend: {e}")
|
||||
2
frontend/requirements.txt
Normal file
2
frontend/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
streamlit==1.35.0
|
||||
requests==2.32.3
|
||||
Loading…
Add table
Add a link
Reference in a new issue