-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (58 loc) · 2.12 KB
/
index.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require('express');
const app = express();
const port = 3000;
const summarizeText = require('./summarize.js');
const generateImage = require('./generate_image.js');
const generateTextFromImage = require('./generate_text_from_image.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) => {
// TODO: handle POST /summarize request
// 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);
});
});
// Adding endpoint to generate image from text
app.post('/generate-image', (req, res) => {
// TODO: handle POST /generate-image request
// get the text_to_summarize property from the request body
const text = req.body.text_to_convert;
// call your summarizeText function, passing in the text from the request
generateImage(text)
.then(response => {
// Set the Content-Type header to "image/jpeg"
res.set('Content-Type', 'image/jpeg');
res.send(response); // Send the summary text as a response to the client
})
.catch(error => {
console.log(error.message);
});
});
// handling image to text analysis
app.post('/image-to-text', (req, res) => {
// TODO: handle POST /summarize request
// get the text_to_summarize property from the request body
const text = req.body.url_to_convert;
// call your summarizeText function, passing in the text from the request
generateTextFromImage(text)
.then(response => {
res.send(response); // Send the summary text as a response to the client
})
.catch(error => {
console.log(error.message);
});
});
// Start the server
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}/`);
});