Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +39 -0
- main2.py +59 -0
- requirements.txt +144 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from main2 import search_trials # Importing from main2.py
|
| 3 |
+
|
| 4 |
+
def run_search(age, sex, state, keywords):
|
| 5 |
+
results = search_trials(
|
| 6 |
+
user_age=age,
|
| 7 |
+
user_sex=sex,
|
| 8 |
+
user_state=state,
|
| 9 |
+
user_keywords=keywords
|
| 10 |
+
)
|
| 11 |
+
return results
|
| 12 |
+
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown("# Clinical Trials Search Tool")
|
| 15 |
+
gr.Markdown(
|
| 16 |
+
"Find **recruiting US clinical trials** that match your **age**, **sex**, "
|
| 17 |
+
"**state**, and optional **keywords**."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
with gr.Row():
|
| 21 |
+
age_input = gr.Number(label="Your Age", value=30)
|
| 22 |
+
sex_input = gr.Dropdown(["Male", "Female"], label="Sex", value="Male")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
state_input = gr.Textbox(label="State (full name or abbreviation)", placeholder="e.g., California")
|
| 26 |
+
keywords_input = gr.Textbox(label="Keywords (comma separated)", placeholder="e.g., cancer, diabetes")
|
| 27 |
+
|
| 28 |
+
search_btn = gr.Button("Search Trials")
|
| 29 |
+
|
| 30 |
+
output_table = gr.Dataframe(label="Matching Trials", interactive=False)
|
| 31 |
+
|
| 32 |
+
search_btn.click(
|
| 33 |
+
fn=run_search,
|
| 34 |
+
inputs=[age_input, sex_input, state_input, keywords_input],
|
| 35 |
+
outputs=output_table
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|
main2.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
def search_trials(user_age, user_sex, user_state, user_keywords, csv_path="clinical_trials_cleaned_merged.csv"):
|
| 4 |
+
"""
|
| 5 |
+
Search for recruiting US clinical trials matching the user's demographics & optional keywords.
|
| 6 |
+
Returns ALL available columns from the dataset.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
# === Load dataset ===
|
| 10 |
+
df = pd.read_csv(csv_path)
|
| 11 |
+
|
| 12 |
+
# Drop missing critical columns
|
| 13 |
+
df = df.dropna(subset=["MinimumAge", "MaximumAge", "Sex", "OverallStatus"])
|
| 14 |
+
|
| 15 |
+
# Keep only US & recruiting trials
|
| 16 |
+
df = df[df["LocationCountry"] == "United States"]
|
| 17 |
+
df = df[df["OverallStatus"].str.lower() == "recruiting"]
|
| 18 |
+
|
| 19 |
+
# Convert ages to numeric
|
| 20 |
+
def parse_age(age_str):
|
| 21 |
+
if pd.isnull(age_str):
|
| 22 |
+
return None
|
| 23 |
+
parts = str(age_str).split()
|
| 24 |
+
try:
|
| 25 |
+
return int(parts[0])
|
| 26 |
+
except:
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
df["MinAgeNum"] = df["MinimumAge"].apply(parse_age)
|
| 30 |
+
df["MaxAgeNum"] = df["MaximumAge"].apply(parse_age)
|
| 31 |
+
|
| 32 |
+
# Prepare user's keywords list
|
| 33 |
+
if isinstance(user_keywords, str):
|
| 34 |
+
keywords = [k.strip().lower() for k in user_keywords.split(",") if k.strip()]
|
| 35 |
+
elif isinstance(user_keywords, list):
|
| 36 |
+
keywords = [str(k).strip().lower() for k in user_keywords if str(k).strip()]
|
| 37 |
+
else:
|
| 38 |
+
keywords = []
|
| 39 |
+
|
| 40 |
+
# === Create masks ===
|
| 41 |
+
sex_mask = df["Sex"].str.lower().isin([str(user_sex).lower(), "all"])
|
| 42 |
+
age_mask = (df["MinAgeNum"] <= int(user_age)) & (df["MaxAgeNum"] >= int(user_age))
|
| 43 |
+
state_mask = df["LocationState"].str.lower() == str(user_state).lower()
|
| 44 |
+
|
| 45 |
+
if keywords:
|
| 46 |
+
def row_matches_any_keyword(row):
|
| 47 |
+
row_as_str = " ".join(str(x).lower() for x in row.values if pd.notnull(x))
|
| 48 |
+
return any(k in row_as_str for k in keywords)
|
| 49 |
+
keyword_mask = df.apply(row_matches_any_keyword, axis=1)
|
| 50 |
+
else:
|
| 51 |
+
keyword_mask = True
|
| 52 |
+
|
| 53 |
+
# Apply all filters and return ALL columns
|
| 54 |
+
filtered_df = df[sex_mask & age_mask & state_mask & keyword_mask].reset_index(drop=True)
|
| 55 |
+
|
| 56 |
+
# Drop helper numeric age cols if you don’t want them visible
|
| 57 |
+
filtered_df = filtered_df.drop(columns=["MinAgeNum", "MaxAgeNum"], errors="ignore")
|
| 58 |
+
|
| 59 |
+
return filtered_df
|
requirements.txt
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|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.2.2
|
| 9 |
+
bcrypt==4.3.0
|
| 10 |
+
bibtexparser==1.4.3
|
| 11 |
+
boto3==1.40.5
|
| 12 |
+
botocore==1.40.5
|
| 13 |
+
Brotli==1.1.0
|
| 14 |
+
certifi==2025.8.3
|
| 15 |
+
cffi==1.17.1
|
| 16 |
+
charset-normalizer==3.4.2
|
| 17 |
+
click==8.2.1
|
| 18 |
+
comm==0.2.3
|
| 19 |
+
contourpy==1.3.3
|
| 20 |
+
cryptography==45.0.6
|
| 21 |
+
cycler==0.12.1
|
| 22 |
+
debugpy==1.8.16
|
| 23 |
+
decorator==5.2.1
|
| 24 |
+
dnspython==2.7.0
|
| 25 |
+
emmet-core==0.84.9
|
| 26 |
+
executing==2.2.0
|
| 27 |
+
fastapi==0.116.1
|
| 28 |
+
ffmpy==0.6.1
|
| 29 |
+
filelock==3.18.0
|
| 30 |
+
fonttools==4.59.0
|
| 31 |
+
fsspec==2025.7.0
|
| 32 |
+
gradio==5.42.0
|
| 33 |
+
gradio_client==1.11.1
|
| 34 |
+
groovy==0.1.2
|
| 35 |
+
h11==0.16.0
|
| 36 |
+
hf-xet==1.1.7
|
| 37 |
+
httpcore==1.0.9
|
| 38 |
+
httpx==0.28.1
|
| 39 |
+
huggingface-hub==0.34.4
|
| 40 |
+
idna==3.10
|
| 41 |
+
invoke==2.2.0
|
| 42 |
+
ipykernel==6.30.1
|
| 43 |
+
ipython==9.4.0
|
| 44 |
+
ipython_pygments_lexers==1.1.1
|
| 45 |
+
jedi==0.19.2
|
| 46 |
+
Jinja2==3.1.6
|
| 47 |
+
jmespath==1.0.1
|
| 48 |
+
joblib==1.5.1
|
| 49 |
+
jsonlines==4.0.0
|
| 50 |
+
jsonschema==4.25.0
|
| 51 |
+
jsonschema-specifications==2025.4.1
|
| 52 |
+
jupyter_client==8.6.3
|
| 53 |
+
jupyter_core==5.8.1
|
| 54 |
+
kiwisolver==1.4.8
|
| 55 |
+
latexcodec==3.0.1
|
| 56 |
+
maggma==0.71.5
|
| 57 |
+
markdown-it-py==3.0.0
|
| 58 |
+
MarkupSafe==3.0.2
|
| 59 |
+
matplotlib==3.10.5
|
| 60 |
+
matplotlib-inline==0.1.7
|
| 61 |
+
mdurl==0.1.2
|
| 62 |
+
mongomock==4.3.0
|
| 63 |
+
monty==2025.3.3
|
| 64 |
+
mp-api==0.45.8
|
| 65 |
+
mpmath==1.3.0
|
| 66 |
+
msgpack==1.1.1
|
| 67 |
+
narwhals==2.0.1
|
| 68 |
+
nest-asyncio==1.6.0
|
| 69 |
+
networkx==3.5
|
| 70 |
+
numpy==2.3.2
|
| 71 |
+
orjson==3.11.1
|
| 72 |
+
packaging==25.0
|
| 73 |
+
palettable==3.3.3
|
| 74 |
+
pandas==2.3.1
|
| 75 |
+
paramiko==4.0.0
|
| 76 |
+
parso==0.8.4
|
| 77 |
+
pexpect==4.9.0
|
| 78 |
+
pillow==11.3.0
|
| 79 |
+
platformdirs==4.3.8
|
| 80 |
+
plotly==6.2.0
|
| 81 |
+
prompt_toolkit==3.0.51
|
| 82 |
+
psutil==7.0.0
|
| 83 |
+
ptyprocess==0.7.0
|
| 84 |
+
PubChemPy==1.0.4
|
| 85 |
+
pure_eval==0.2.3
|
| 86 |
+
pybtex==0.25.1
|
| 87 |
+
pycparser==2.22
|
| 88 |
+
pydantic==2.11.7
|
| 89 |
+
pydantic-settings==2.10.1
|
| 90 |
+
pydantic_core==2.33.2
|
| 91 |
+
pydash==8.0.5
|
| 92 |
+
pydub==0.25.1
|
| 93 |
+
Pygments==2.19.2
|
| 94 |
+
pymatgen==2025.6.14
|
| 95 |
+
pymongo==4.10.1
|
| 96 |
+
PyNaCl==1.5.0
|
| 97 |
+
pyparsing==3.2.3
|
| 98 |
+
python-dateutil==2.9.0.post0
|
| 99 |
+
python-dotenv==1.1.1
|
| 100 |
+
python-multipart==0.0.20
|
| 101 |
+
pytz==2025.2
|
| 102 |
+
PyYAML==6.0.2
|
| 103 |
+
pyzmq==27.0.1
|
| 104 |
+
rdkit==2025.3.5
|
| 105 |
+
referencing==0.36.2
|
| 106 |
+
requests==2.32.4
|
| 107 |
+
rich==14.1.0
|
| 108 |
+
rpds-py==0.27.0
|
| 109 |
+
ruamel.yaml==0.18.14
|
| 110 |
+
ruamel.yaml.clib==0.2.12
|
| 111 |
+
ruff==0.12.8
|
| 112 |
+
s3transfer==0.13.1
|
| 113 |
+
safehttpx==0.1.6
|
| 114 |
+
scikit-learn==1.7.1
|
| 115 |
+
scipy==1.16.1
|
| 116 |
+
semantic-version==2.10.0
|
| 117 |
+
sentinels==1.0.0
|
| 118 |
+
setuptools==80.9.0
|
| 119 |
+
shellingham==1.5.4
|
| 120 |
+
six==1.17.0
|
| 121 |
+
smart_open==7.3.0.post1
|
| 122 |
+
sniffio==1.3.1
|
| 123 |
+
spglib==2.6.0
|
| 124 |
+
sshtunnel==0.4.0
|
| 125 |
+
stack-data==0.6.3
|
| 126 |
+
starlette==0.47.2
|
| 127 |
+
sympy==1.14.0
|
| 128 |
+
tabulate==0.9.0
|
| 129 |
+
threadpoolctl==3.6.0
|
| 130 |
+
tomlkit==0.13.3
|
| 131 |
+
tornado==6.5.1
|
| 132 |
+
tqdm==4.67.1
|
| 133 |
+
traitlets==5.14.3
|
| 134 |
+
typer==0.16.0
|
| 135 |
+
typing-inspection==0.4.1
|
| 136 |
+
typing_extensions==4.14.1
|
| 137 |
+
tzdata==2025.2
|
| 138 |
+
uncertainties==3.2.3
|
| 139 |
+
urllib3==2.5.0
|
| 140 |
+
uvicorn==0.35.0
|
| 141 |
+
wcwidth==0.2.13
|
| 142 |
+
websockets==15.0.1
|
| 143 |
+
wrapt==1.17.2
|
| 144 |
+
xgboost==3.0.3
|