-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (36 loc) · 1.1 KB
/
index.js
File metadata and controls
41 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express');
const app = express();
const port = 3000;
const summarizeText = require('./summarize.js');
const classifyText = require('./classify.js');
// Parses JSON bodies (as sent by API clients)
app.use(express.json());
// Serves static files from the 'public' directory
app.use(express.static('public'));
// Handle POST requests to the '/summarize' endpoint
app.post('/summarize', (req, res) => {
// get the text_to_summarize property from the request body
const text = req.body.text_to_summarize;
// call your summarizeText function, passing in the text from the request
summarizeText(text)
.then(response => {
res.send(response); // Send the summary text as a response to the client
})
.catch(error => {
console.log(error.message);
});
});
app.post('/classify',(req,res)=>{
const text=req.body.text_to_classify;
classifyText(text)
.then(response=>{
res.send(response);
})
.catch(error=>{
console.log(error.message);
})
})
// Start the server
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});