-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
35 lines (30 loc) · 1.11 KB
/
app.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
//Application to generate content based on input prompts.
//The app uses Google cloud Vertex AI
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const { generateBlog } = require("./vertex");
require('dotenv').config();
const app = express();
const PORT = 80;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "view")));
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "view"));
//Running the app on the specified port
app.listen(PORT, () => {
console.log(`App started on localhost:${PORT} `);
});
//Load index.html with textboxes to take prompt inputs
app.get("/", async (req, res) => {
res.sendFile(path.join(__dirname, "view", "index.html"));
});
//Call generate-blog endpoint to fetch results from vertex AI apis
app.post("/generate-blog", async (req, res) => {
const result = await generateBlog(req.body.prompt);
return res.render("result", { result, prompt: req.body.prompt });
});
app.get("/generate-blog", async (req, res) => {
return res.redirect("/");
});