Spaces:
Runtime error
Runtime error
Vaishnav14220 commited on
Commit ·
e1f2b89
1
Parent(s): ea475f3
Fix autocomplete: use filterable Dropdown instead of Textbox for native autocomplete support
Browse files367 unmodified lines3683693703713723733743753763773783793803813823833843853863873883893903913923934 unmodified lines3983994004014024034044054064074081 unmodified line4104114124134144154164174184194204214224231 unmodified line425426427428429430431432433434435436437438439440441442443444445446447448449450451367 unmodified linesdescription="Convert an input SMILES string to its canonical form.",)# Function to get autocomplete suggestionsdef get_suggestions(text):"""Return top 10 matching chemical names"""if not text or len(text) < 1:return COMMON_CHEMICALS[:10]text_lower = text.lower()matches = [chem for chem in COMMON_CHEMICALS if chem.lower().startswith(text_lower)]return matches[:10] if matches else COMMON_CHEMICALS[:10]name_interface = gr.Interface(fn=name_to_smiles,inputs=gr.Textbox(label="Chemical Name",placeholder="Start typing... (e.g., asp, caf, ben)",info="Type at least 1 character to see suggestions"),outputs=gr.Textbox(label="SMILES"),api_name="name_to_smiles",description="Convert a chemical name to SMILES notation. Start typing to see autocomplete suggestions!",examples=[["aspirin"], ["caffeine"], ["benzene"], ["ethanol"], ["glucose"]],)4 unmodified lineswith gr.Row():with gr.Column():chem_name_input = gr.Textbox(label="Chemical Name",placeholder="Start typing... (e.g., benzene, aspirin, water)",info="Type 1+ characters to see suggestions",elem_id="chem_name")orbital_checkbox = gr.Checkbox(label="Show Electron Orbitals (s, p, d shapes)",1 unmodified lineinfo="Toggle to see s-orbitals (spheres), p-orbitals (dumbbells), and d-orbitals (cloverleaf) around atoms")submit_btn = gr.Button("Generate 3D Molecule", variant="primary")# Autocomplete dropdownsuggestions_dropdown = gr.Dropdown(choices=COMMON_CHEMICALS[:10],label="Quick Select (or type above)",interactive=True,allow_custom_value=True)with gr.Row():html_output = gr.HTML(label="2D Structure")1 unmodified linewith gr.Row():plot_output = gr.Plot(label="3D Interactive Molecule Viewer - Rotate and Zoom!")# Update suggestions as user typesdef update_suggestions(text):suggestions = get_suggestions(text)return gr.Dropdown(choices=suggestions)# Update text input when dropdown selection changesdef update_from_dropdown(selected):return selectedchem_name_input.change(fn=update_suggestions,inputs=[chem_name_input],outputs=[suggestions_dropdown])suggestions_dropdown.change(fn=update_from_dropdown,inputs=[suggestions_dropdown],outputs=[chem_name_input])submit_btn.click(fn=name_to_3d_molecule,inputs=[chem_name_input, orbital_checkbox],367 unmodified lines3683693703713723733743753763773783793803813823834 unmodified lines3883893903913923933943953963973983994004014021 unmodified line4044054064074084091 unmodified line411412413414415416367 unmodified linesdescription="Convert an input SMILES string to its canonical form.",)name_interface = gr.Interface(fn=name_to_smiles,inputs=gr.Textbox(label="Chemical Name",placeholder="Enter chemical name (e.g., aspirin, caffeine, benzene)",info="Enter the full chemical name"),outputs=gr.Textbox(label="SMILES"),api_name="name_to_smiles",description="Convert a chemical name to SMILES notation.",examples=[["aspirin"], ["caffeine"], ["benzene"], ["ethanol"], ["glucose"]],)4 unmodified lineswith gr.Row():with gr.Column():# Use Dropdown with allow_custom_value for autocompletechem_name_input = gr.Dropdown(choices=COMMON_CHEMICALS,label="Chemical Name - Type to Search",info="Start typing to filter from 100+ chemicals",allow_custom_value=True,value=None,interactive=True,filterable=True)orbital_checkbox = gr.Checkbox(label="Show Electron Orbitals (s, p, d shapes)",1 unmodified lineinfo="Toggle to see s-orbitals (spheres), p-orbitals (dumbbells), and d-orbitals (cloverleaf) around atoms")submit_btn = gr.Button("Generate 3D Molecule", variant="primary")with gr.Row():html_output = gr.HTML(label="2D Structure")1 unmodified linewith gr.Row():plot_output = gr.Plot(label="3D Interactive Molecule Viewer - Rotate and Zoom!")submit_btn.click(fn=name_to_3d_molecule,inputs=[chem_name_input, orbital_checkbox],
app.py+12-47