trialgpt-api-ui / streamlit_app.py
tannu038's picture
Create streamlit_app.py
7ee7c16 verified
import streamlit as st
import requests
st.title("TrialGPT API Tester πŸ’Š")
api_base = "http://localhost:8000"
# --- Section 1: /retrieve ---
st.header("πŸ” /retrieve")
query_text = st.text_input("Enter your clinical query:", "Obesity treatment for children")
if st.button("Search Trials"):
res = requests.post(f"{api_base}/retrieve", json={"text": query_text})
if res.ok:
results = res.json()["matched_trials"]
st.success(f"βœ… Found {len(results)} trials")
for trial in results:
st.json(trial)
else:
st.error("❌ Error retrieving trials")
# --- Section 2: /extract-timeline/ ---
st.header("πŸ“… /extract-timeline/")
timeline_text = st.text_area("Enter study text for timeline extraction:", "This study includes a 2-week screening, 12-week treatment, and 6-week follow-up.")
if st.button("Extract Timeline"):
res = requests.post(f"{api_base}/extract-timeline/", json={"text": timeline_text})
if res.ok:
st.write("πŸ“‹ Timeline:")
st.json(res.json())
else:
st.error("❌ Error extracting timeline")
# --- Section 3: /trial/{nct_id} ---
st.header("πŸ”¬ /trial/{nct_id}")
trial_id = st.text_input("Enter NCT ID:", "NCT01234567")
if st.button("Get Trial Details"):
res = requests.get(f"{api_base}/trial/{trial_id}")
if res.ok:
st.write("πŸ” Trial Details:")
st.json(res.json())
else:
st.error("❌ Error fetching trial details")