Vaishnav14220 commited on
Commit
5dbfa97
·
1 Parent(s): fb9b959

Replace dataframe with HTML table including 'Fix with AI' button in first column

Browse files
Files changed (1) hide show
  1. app.py +50 -5
app.py CHANGED
@@ -253,11 +253,56 @@ with gr.Blocks(title="Organic Reactions Search") as demo:
253
 
254
  with gr.Tab("View All Reactions (Table)"):
255
  gr.Markdown("Browse all 828 reactions in a tabular format.")
256
- # Prepare data for table display
257
- table_data = df[['corrected_name', 'general_reactants', 'reactants_smiles', 'general_reagents', 'reagents_smiles', 'general_products', 'products_smiles']].copy()
258
- table_data['description'] = df['description'].str[:100] + '...' # Truncate description
259
- table_data.columns = ['Reaction Name', 'Reactants', 'Reactants SMILES', 'Reagents', 'Reagents SMILES', 'Products', 'Products SMILES', 'Description (truncated)']
260
- table_output = gr.Dataframe(value=table_data, label="All Reactions", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  gr.Markdown("""
262
  ## API Endpoints
263
 
 
253
 
254
  with gr.Tab("View All Reactions (Table)"):
255
  gr.Markdown("Browse all 828 reactions in a tabular format.")
256
+
257
+ # Create HTML table with buttons
258
+ def create_reactions_table():
259
+ html = """
260
+ <table style="width:100%; border-collapse: collapse;">
261
+ <thead>
262
+ <tr style="background-color: #f2f2f2;">
263
+ <th style="border: 1px solid #ddd; padding: 8px;">Action</th>
264
+ <th style="border: 1px solid #ddd; padding: 8px;">Reaction Name</th>
265
+ <th style="border: 1px solid #ddd; padding: 8px;">Reactants</th>
266
+ <th style="border: 1px solid #ddd; padding: 8px;">Reactants SMILES</th>
267
+ <th style="border: 1px solid #ddd; padding: 8px;">Reagents</th>
268
+ <th style="border: 1px solid #ddd; padding: 8px;">Reagents SMILES</th>
269
+ <th style="border: 1px solid #ddd; padding: 8px;">Products</th>
270
+ <th style="border: 1px solid #ddd; padding: 8px;">Products SMILES</th>
271
+ <th style="border: 1px solid #ddd; padding: 8px;">Description</th>
272
+ </tr>
273
+ </thead>
274
+ <tbody>
275
+ """
276
+
277
+ for idx, row in df.iterrows():
278
+ reaction_name = row['corrected_name']
279
+ reactants = row['general_reactants'] if pd.notna(row['general_reactants']) else 'N/A'
280
+ reactants_smiles = ', '.join([s for s in row['reactants_smiles'] if s is not None]) if row['reactants_smiles'] else 'N/A'
281
+ reagents = row['general_reagents'] if pd.notna(row['general_reagents']) else 'N/A'
282
+ reagents_smiles = ', '.join([s for s in row['reagents_smiles'] if s is not None]) if row['reagents_smiles'] else 'N/A'
283
+ products = row['general_products'] if pd.notna(row['general_products']) else 'N/A'
284
+ products_smiles = ', '.join([s for s in row['products_smiles'] if s is not None]) if row['products_smiles'] else 'N/A'
285
+ description = row['description'][:100] + '...' if len(row['description']) > 100 else row['description']
286
+
287
+ html += f"""
288
+ <tr>
289
+ <td style="border: 1px solid #ddd; padding: 8px;"><button onclick="alert('Fix with AI functionality for {reaction_name} would be implemented here')">Fix with AI</button></td>
290
+ <td style="border: 1px solid #ddd; padding: 8px;">{reaction_name}</td>
291
+ <td style="border: 1px solid #ddd; padding: 8px;">{reactants}</td>
292
+ <td style="border: 1px solid #ddd; padding: 8px; font-family: monospace; font-size: 12px;">{reactants_smiles}</td>
293
+ <td style="border: 1px solid #ddd; padding: 8px;">{reagents}</td>
294
+ <td style="border: 1px solid #ddd; padding: 8px; font-family: monospace; font-size: 12px;">{reagents_smiles}</td>
295
+ <td style="border: 1px solid #ddd; padding: 8px;">{products}</td>
296
+ <td style="border: 1px solid #ddd; padding: 8px; font-family: monospace; font-size: 12px;">{products_smiles}</td>
297
+ <td style="border: 1px solid #ddd; padding: 8px;">{description}</td>
298
+ </tr>
299
+ """
300
+
301
+ html += "</tbody></table>"
302
+ return html
303
+
304
+ table_html = create_reactions_table()
305
+ table_output = gr.HTML(value=table_html, label="All Reactions Database")
306
  gr.Markdown("""
307
  ## API Endpoints
308