Spaces:
Sleeping
Sleeping
Vaishnav14220 commited on
Commit ·
eff21ae
1
Parent(s): 40e2fb4
Fix API error by removing invalid api_name from Button components
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ from fuzzywuzzy import process
|
|
| 7 |
ds = load_dataset("smitathkr1/organic_reactions_enhanced")
|
| 8 |
df = ds['train'].to_pandas()
|
| 9 |
|
| 10 |
-
|
| 11 |
# Precompute unique values for autocomplete
|
| 12 |
reaction_names = df['name'].unique().tolist()
|
| 13 |
all_reactants = []
|
|
@@ -84,19 +83,19 @@ with gr.Blocks(title="Organic Reactions Search") as demo:
|
|
| 84 |
with gr.Tab("Search by Reaction Name"):
|
| 85 |
reaction_input = gr.Textbox(label="Reaction Name", placeholder="e.g., appel-reaction")
|
| 86 |
reaction_output = gr.Markdown(label="Result")
|
| 87 |
-
reaction_btn = gr.Button("Search"
|
| 88 |
reaction_btn.click(search_by_reaction_name, inputs=reaction_input, outputs=reaction_output)
|
| 89 |
|
| 90 |
with gr.Tab("Search by Reactant"):
|
| 91 |
reactant_input = gr.Textbox(label="Reactant", placeholder="e.g., alcohol")
|
| 92 |
reactant_output = gr.Markdown(label="Results")
|
| 93 |
-
reactant_btn = gr.Button("Search"
|
| 94 |
reactant_btn.click(search_by_reactant, inputs=reactant_input, outputs=reactant_output)
|
| 95 |
|
| 96 |
with gr.Tab("Search by Product"):
|
| 97 |
product_input = gr.Textbox(label="Product", placeholder="e.g., ester")
|
| 98 |
product_output = gr.Markdown(label="Results")
|
| 99 |
-
product_btn = gr.Button("Search"
|
| 100 |
product_btn.click(search_by_product, inputs=product_input, outputs=product_output)
|
| 101 |
|
| 102 |
with gr.Tab("API Documentation"):
|
|
@@ -105,33 +104,27 @@ with gr.Blocks(title="Organic Reactions Search") as demo:
|
|
| 105 |
|
| 106 |
This Gradio app exposes the following functions as API endpoints. You can call them via HTTP POST requests to the `/api/predict` endpoint.
|
| 107 |
|
| 108 |
-
### Search by Reaction Name
|
| 109 |
-
- **Function**: `search_by_reaction_name`
|
| 110 |
- **Input**: `query` (string) - The reaction name to search
|
| 111 |
- **Output**: Markdown string with reaction details
|
| 112 |
|
| 113 |
-
### Search by Reactant
|
| 114 |
-
- **Function**: `search_by_reactant`
|
| 115 |
- **Input**: `reactant` (string) - The reactant to search for
|
| 116 |
- **Output**: Markdown string with matching reactions
|
| 117 |
|
| 118 |
-
### Search by Product
|
| 119 |
-
- **Function**: `search_by_product`
|
| 120 |
- **Input**: `product` (string) - The product to search for
|
| 121 |
- **Output**: Markdown string with matching reactions
|
| 122 |
|
| 123 |
-
### Autocomplete Reaction Names
|
| 124 |
-
- **Function**: `get_autocomplete_reactions`
|
| 125 |
- **Input**: `query` (string) - Partial reaction name
|
| 126 |
- **Output**: List of matching reaction names
|
| 127 |
|
| 128 |
-
### Autocomplete Reactants
|
| 129 |
-
- **Function**: `get_autocomplete_reactants`
|
| 130 |
- **Input**: `query` (string) - Partial reactant name
|
| 131 |
- **Output**: List of matching reactants
|
| 132 |
|
| 133 |
-
### Autocomplete Products
|
| 134 |
-
- **Function**: `get_autocomplete_products`
|
| 135 |
- **Input**: `query` (string) - Partial product name
|
| 136 |
- **Output**: List of matching products
|
| 137 |
|
|
@@ -142,7 +135,7 @@ with gr.Blocks(title="Organic Reactions Search") as demo:
|
|
| 142 |
-d '{"fn_index": 0, "data": ["appel-reaction"]}'
|
| 143 |
```
|
| 144 |
|
| 145 |
-
Note: `fn_index` corresponds to the function order in the app.
|
| 146 |
""")
|
| 147 |
|
| 148 |
if __name__ == "__main__":
|
|
|
|
| 7 |
ds = load_dataset("smitathkr1/organic_reactions_enhanced")
|
| 8 |
df = ds['train'].to_pandas()
|
| 9 |
|
|
|
|
| 10 |
# Precompute unique values for autocomplete
|
| 11 |
reaction_names = df['name'].unique().tolist()
|
| 12 |
all_reactants = []
|
|
|
|
| 83 |
with gr.Tab("Search by Reaction Name"):
|
| 84 |
reaction_input = gr.Textbox(label="Reaction Name", placeholder="e.g., appel-reaction")
|
| 85 |
reaction_output = gr.Markdown(label="Result")
|
| 86 |
+
reaction_btn = gr.Button("Search")
|
| 87 |
reaction_btn.click(search_by_reaction_name, inputs=reaction_input, outputs=reaction_output)
|
| 88 |
|
| 89 |
with gr.Tab("Search by Reactant"):
|
| 90 |
reactant_input = gr.Textbox(label="Reactant", placeholder="e.g., alcohol")
|
| 91 |
reactant_output = gr.Markdown(label="Results")
|
| 92 |
+
reactant_btn = gr.Button("Search")
|
| 93 |
reactant_btn.click(search_by_reactant, inputs=reactant_input, outputs=reactant_output)
|
| 94 |
|
| 95 |
with gr.Tab("Search by Product"):
|
| 96 |
product_input = gr.Textbox(label="Product", placeholder="e.g., ester")
|
| 97 |
product_output = gr.Markdown(label="Results")
|
| 98 |
+
product_btn = gr.Button("Search")
|
| 99 |
product_btn.click(search_by_product, inputs=product_input, outputs=product_output)
|
| 100 |
|
| 101 |
with gr.Tab("API Documentation"):
|
|
|
|
| 104 |
|
| 105 |
This Gradio app exposes the following functions as API endpoints. You can call them via HTTP POST requests to the `/api/predict` endpoint.
|
| 106 |
|
| 107 |
+
### Search by Reaction Name (fn_index: 0)
|
|
|
|
| 108 |
- **Input**: `query` (string) - The reaction name to search
|
| 109 |
- **Output**: Markdown string with reaction details
|
| 110 |
|
| 111 |
+
### Search by Reactant (fn_index: 1)
|
|
|
|
| 112 |
- **Input**: `reactant` (string) - The reactant to search for
|
| 113 |
- **Output**: Markdown string with matching reactions
|
| 114 |
|
| 115 |
+
### Search by Product (fn_index: 2)
|
|
|
|
| 116 |
- **Input**: `product` (string) - The product to search for
|
| 117 |
- **Output**: Markdown string with matching reactions
|
| 118 |
|
| 119 |
+
### Autocomplete Reaction Names (fn_index: 3)
|
|
|
|
| 120 |
- **Input**: `query` (string) - Partial reaction name
|
| 121 |
- **Output**: List of matching reaction names
|
| 122 |
|
| 123 |
+
### Autocomplete Reactants (fn_index: 4)
|
|
|
|
| 124 |
- **Input**: `query` (string) - Partial reactant name
|
| 125 |
- **Output**: List of matching reactants
|
| 126 |
|
| 127 |
+
### Autocomplete Products (fn_index: 5)
|
|
|
|
| 128 |
- **Input**: `query` (string) - Partial product name
|
| 129 |
- **Output**: List of matching products
|
| 130 |
|
|
|
|
| 135 |
-d '{"fn_index": 0, "data": ["appel-reaction"]}'
|
| 136 |
```
|
| 137 |
|
| 138 |
+
Note: `fn_index` corresponds to the function order in the app (0-based).
|
| 139 |
""")
|
| 140 |
|
| 141 |
if __name__ == "__main__":
|