Skip to content

Commit bc11ffa

Browse files
committed
Show uploaded file from pyodide FS
1 parent 92f5665 commit bc11ffa

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/components/notebook/cell/CsvUploadButton.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,14 @@ export function CsvUploadButton({
3030
const { addCell } = useAddCell();
3131
const { uploadFile, isUploading } = useFileUpload({
3232
notebookId: store.storeId,
33-
onFileUploaded: (artifactId, fileName) => {
33+
onFileUploaded: ({ fileName }) => {
3434
toast.success(`File uploaded: ${fileName}`);
3535
// Create a new code cell with CSV loading code
3636
const newCellId = addCell(cellId, "code", position);
3737

3838
// Set the cell content to load the CSV
3939
const csvCode = `import pandas as pd
40-
import pyodide
41-
42-
# Load CSV file: ${fileName}
43-
dataset_url = "/api/artifacts/${artifactId}"
44-
df = pd.read_csv(pyodide.http.open_url(dataset_url))
45-
46-
# Display basic info about the dataset
47-
print(f"Dataset shape: {df.shape}")
40+
df = pd.read_csv('${fileName}')
4841
df.head()`;
4942

5043
store.commit(

src/hooks/useFileUpload.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import { events } from "@runtimed/schema";
66

77
interface FileUploadOptions {
88
notebookId: string;
9-
onFileUploaded?: (artifactId: string, fileName: string) => void;
9+
onFileUploaded?: ({
10+
artifactId,
11+
fileName,
12+
}: {
13+
artifactId: string;
14+
fileName: string;
15+
}) => void;
1016
}
1117

1218
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -67,7 +73,7 @@ export const useFileUpload = ({
6773
);
6874

6975
setIsUploading(false);
70-
onFileUploaded?.(result.artifactId, file.name);
76+
onFileUploaded?.({ artifactId: result.artifactId, fileName: file.name });
7177

7278
return result.artifactId;
7379
},

0 commit comments

Comments
 (0)