Update streamlit_slop_with_models.py
This commit is contained in:
parent
5b50e5c9dc
commit
eefb10f8ed
1 changed files with 34 additions and 2 deletions
|
|
@ -190,6 +190,8 @@ def memory_interface():
|
|||
|
||||
def resources_interface():
|
||||
st.header("Resources")
|
||||
|
||||
# Fetch available resources
|
||||
try:
|
||||
response = requests.get(f"{BASE_URL}/resources", timeout=5)
|
||||
response.raise_for_status()
|
||||
|
|
@ -202,15 +204,45 @@ def resources_interface():
|
|||
st.write("No resources available.")
|
||||
return
|
||||
|
||||
resource_id = st.selectbox("Select resource", [r["id"] for r in resources])
|
||||
# Select resource for GET
|
||||
resource_id = st.selectbox("Select resource to get", [r["id"] for r in resources])
|
||||
if st.button("Get Resource"):
|
||||
try:
|
||||
response = requests.get(f"{BASE_URL}/resources/{resource_id}", timeout=5)
|
||||
response.raise_for_status()
|
||||
st.write(response.json().get("content", response.json()))
|
||||
result = response.json()
|
||||
if "error" in result:
|
||||
st.error(f"Error: {result['error']}")
|
||||
elif "resources" in result: # Prefix search result
|
||||
st.write("Nested Resources Found:")
|
||||
for res in result["resources"]:
|
||||
st.write(f"- **{res['id']}**: {res['content']}")
|
||||
else: # Exact match
|
||||
st.write(f"**{result['id']}**: {result['content']}")
|
||||
except requests.RequestException as e:
|
||||
st.error(f"Error: {str(e)}")
|
||||
|
||||
# Form for updating/creating a resource
|
||||
st.subheader("Update or Create Resource")
|
||||
with st.form(key="resource_form"):
|
||||
new_resource_id = st.text_input("Resource ID", value=resource_id)
|
||||
content = st.text_area("Content", height=100)
|
||||
submit_button = st.form_submit_button(label="Update/Create", type="primary")
|
||||
|
||||
if submit_button and new_resource_id and content:
|
||||
try:
|
||||
response = requests.put(
|
||||
f"{BASE_URL}/resources/{new_resource_id}",
|
||||
json={"content": content},
|
||||
timeout=5
|
||||
)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
st.success(f"Resource {result['resource']['id']} updated/created successfully!")
|
||||
st.write(f"**{result['resource']['id']}**: {result['resource']['content']}")
|
||||
except requests.RequestException as e:
|
||||
st.error(f"Error: {str(e)}")
|
||||
|
||||
|
||||
def pay_interface():
|
||||
st.header("Pay")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue