Spaces:
Runtime error
Runtime error
Download frontend/src/components/tools/PredictYieldForm.tsx from SII-gelingli/echem-agent: direct link, hf CLI and curl.
- Browser
- Download file 3.4 kB
-
https://huggingface.co/spaces/SII-gelingli/echem-agent/resolve/main/frontend/src/components/tools/PredictYieldForm.tsx
- Command line
-
hf download hf://spaces/SII-gelingli/echem-agent/frontend/src/components/tools/PredictYieldForm.tsx
-
curl -L -o PredictYieldForm.tsx https://huggingface.co/spaces/SII-gelingli/echem-agent/resolve/main/frontend/src/components/tools/PredictYieldForm.tsx
3.4 kB
| import { useState } from 'react'; | |
| import { Form, Input, InputNumber, Button, Alert, Card, Select, Table } from 'antd'; | |
| import { predictYield } from '../../api/tools'; | |
| import { ELECTRODE_NAMES, CELL_TYPE_NAMES } from '../../utils/types'; | |
| export default function PredictYieldForm() { | |
| const [loading, setLoading] = useState(false); | |
| const [result, setResult] = useState<any>(null); | |
| const [error, setError] = useState(''); | |
| const electrodeOptions = Object.entries(ELECTRODE_NAMES) | |
| .filter(([k]) => Number(k) < 18) | |
| .map(([k, v]) => ({ value: Number(k), label: v })); | |
| const cellOptions = Object.entries(CELL_TYPE_NAMES) | |
| .filter(([k]) => Number(k) < 5) | |
| .map(([k, v]) => ({ value: Number(k), label: v })); | |
| const onFinish = async (values: any) => { | |
| setLoading(true); | |
| setError(''); | |
| try { | |
| const data = await predictYield(values.reaction_smiles, [ | |
| { | |
| solvent_smiles: values.solvent_smiles, | |
| electrolyte_smiles: values.electrolyte_smiles, | |
| anode_index: values.anode_index ?? 0, | |
| cathode_index: values.cathode_index ?? 0, | |
| cell_type_index: values.cell_type_index ?? 0, | |
| }, | |
| ]); | |
| setResult(data); | |
| } catch (err: any) { | |
| setError(err.response?.data?.detail || 'Failed'); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| return ( | |
| <div> | |
| <Form onFinish={onFinish} layout="vertical" initialValues={{ anode_index: 0, cathode_index: 0, cell_type_index: 0 }}> | |
| <Form.Item name="reaction_smiles" label="Reaction SMILES" rules={[{ required: true }]}> | |
| <Input placeholder="reactants>>products" /> | |
| </Form.Item> | |
| <Form.Item name="solvent_smiles" label="Solvent SMILES" rules={[{ required: true }]}> | |
| <Input placeholder="e.g. CO (methanol)" /> | |
| </Form.Item> | |
| <Form.Item name="electrolyte_smiles" label="Electrolyte SMILES" rules={[{ required: true }]}> | |
| <Input placeholder="e.g. [N+](=O)([O-])O" /> | |
| </Form.Item> | |
| <Form.Item name="anode_index" label="Anode"> | |
| <Select options={electrodeOptions} /> | |
| </Form.Item> | |
| <Form.Item name="cathode_index" label="Cathode"> | |
| <Select options={electrodeOptions} /> | |
| </Form.Item> | |
| <Form.Item name="cell_type_index" label="Cell Type"> | |
| <Select options={cellOptions} /> | |
| </Form.Item> | |
| <Button type="primary" htmlType="submit" loading={loading}>Predict Yield</Button> | |
| </Form> | |
| {error && <Alert message={error} type="error" showIcon style={{ marginTop: 16 }} />} | |
| {result && ( | |
| <Card style={{ marginTop: 16 }}> | |
| <Table | |
| size="small" | |
| pagination={false} | |
| dataSource={result.yield_predictions || []} | |
| rowKey={(_, i) => String(i)} | |
| columns={[ | |
| { title: 'Solvent', key: 's', render: (_: any, r: any) => r.conditions?.solvent }, | |
| { title: 'Electrolyte', key: 'e', render: (_: any, r: any) => r.conditions?.electrolyte }, | |
| { title: 'Anode', key: 'a', render: (_: any, r: any) => r.conditions?.anode }, | |
| { title: 'Cathode', key: 'c', render: (_: any, r: any) => r.conditions?.cathode }, | |
| { title: 'Predicted Yield', dataIndex: 'predicted_yield', key: 'y', render: (v: number) => `${v}%` }, | |
| ]} | |
| /> | |
| </Card> | |
| )} | |
| </div> | |
| ); | |
| } | |