kizabgd123 commited on
Commit
6a20c17
·
verified ·
1 Parent(s): 6da3e82

Upload pages/api/parse-notebook.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. pages/api/parse-notebook.js +33 -0
pages/api/parse-notebook.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import formidable from 'formidable';
2
+ import { promises as fs } from 'fs';
3
+ import path from 'path';
4
+ import { NotebookParser } from '../../lib/notebook-parser';
5
+
6
+ export const config = {
7
+ api: {
8
+ bodyParser: false,
9
+ },
10
+ };
11
+
12
+ export default async function handler(req, res) {
13
+ if (req.method !== 'POST') {
14
+ return res.status(405).json({ error: 'Method not allowed' });
15
+ }
16
+
17
+ try {
18
+ const form = new formidable.IncomingForm();
19
+ const [, files] = await form.parse(req);
20
+ const file = files.file[0];
21
+
22
+ const parser = new NotebookParser();
23
+ const parameters = await parser.parseNotebook(file.filepath);
24
+
25
+ // Clean up temp file
26
+ await fs.unlink(file.filepath);
27
+
28
+ res.status(200).json({ parameters });
29
+ } catch (error) {
30
+ console.error('Parse error:', error);
31
+ res.status(500).json({ error: 'Failed to parse notebook' });
32
+ }
33
+ }