Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from main2 import search_trials # Your existing search function | |
| def run_search(age, sex, state, keywords): | |
| # Calls your imported function and returns results in tabular form | |
| results = search_trials( | |
| user_age=age, | |
| user_sex=sex, | |
| user_state=state, | |
| user_keywords=keywords | |
| ) | |
| return results | |
| with gr.Blocks() as demo: | |
| with gr.Tabs() as tabs: | |
| with gr.Tab("Search Trials"): | |
| gr.Markdown("# Clinical Trials Search Tool") | |
| gr.Markdown( | |
| "Find **recruiting US clinical trials** that match your **age**, **sex**, " | |
| "**state**, and optional **keywords**." | |
| ) | |
| with gr.Row(): | |
| age_input = gr.Number(label="Your Age", value=30) | |
| sex_input = gr.Dropdown(["Male", "Female"], label="Sex", value="Male") | |
| with gr.Row(): | |
| state_input = gr.Dropdown([ | |
| "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", | |
| "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", | |
| "Kansas", "Kentucky", "Louisiana", "Maine", "Massachusetts", "Michigan", "Minnesota", | |
| "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", | |
| "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", | |
| "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", | |
| "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", | |
| "Wyoming" | |
| ], label="State (full name or abbreviation)", value="California") | |
| keywords_input = gr.Textbox(label="Keywords (comma separated)", placeholder="e.g., cancer, diabetes") | |
| search_btn = gr.Button("Search Trials") | |
| with gr.Tab("Results"): | |
| output_table = gr.DataFrame(label="Matching Trials", interactive=False) | |
| def show_results(age, sex, state, keywords): | |
| results = run_search(age, sex, state, keywords) | |
| # Return results and switch to results tab (index 1) | |
| return results, gr.Tabs.update(selected=1) | |
| search_btn.click( | |
| fn=show_results, | |
| inputs=[age_input, sex_input, state_input, keywords_input], | |
| outputs=[output_table, tabs] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |