-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a6b798
Showing
9 changed files
with
3,115 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Install | ||
|
||
`npm install` | ||
|
||
--- | ||
|
||
# Things to add | ||
|
||
- Create a config folder with a `.env` file and add the following as `key = value` | ||
- PORT = 2121 (can be any port example: 3000) | ||
- MS_KEY = `your Microsoft Face Endpoint` | ||
- MS_REGION = `your Microsoft Face Key` | ||
|
||
--- | ||
|
||
# Run | ||
|
||
`npm start` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const express = require("express"); | ||
const app = express(); | ||
|
||
require("dotenv").config({ path: "./config/.env" }); | ||
|
||
// pull in the required packages. | ||
const { | ||
TextAnalyticsClient, | ||
AzureKeyCredential, | ||
} = require("@azure/ai-text-analytics"); | ||
|
||
const endpoint = process.env["ENDPOINT"] || "<cognitive services endpoint>"; | ||
const apiKey = process.env["TEXT_ANALYTICS_API_KEY"] || "<api key>"; | ||
|
||
//Server Setup | ||
app.set("view engine", "ejs"); | ||
app.use(express.static("public")); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
//Routes | ||
app.get("/", (req, res) => { | ||
res.render("index.ejs"); | ||
}); | ||
|
||
app.post("/", async (req, res) => { | ||
try { | ||
const documents = [String(req.body.sendText)]; | ||
|
||
console.log("=== Analyze Sentiment Sample ==="); | ||
|
||
const client = new TextAnalyticsClient( | ||
endpoint, | ||
new AzureKeyCredential(apiKey) | ||
); | ||
|
||
const results = await client.analyzeSentiment(documents); | ||
|
||
for (let i = 0; i < results.length; i++) { | ||
const result = results[i]; | ||
console.log(`- Document ${result.id}`); | ||
if (!result.error) { | ||
console.log(`\tDocument text: ${documents[i]}`); | ||
console.log(`\tOverall Sentiment: ${result.sentiment}`); | ||
console.log("\tSentiment confidence scores: ", result.confidenceScores); | ||
console.log("\tSentences"); | ||
for (const { sentiment, confidenceScores, text } of result.sentences) { | ||
console.log(`\t- Sentence text: ${text}`); | ||
console.log(`\t Sentence sentiment: ${sentiment}`); | ||
console.log("\t Confidence scores:", confidenceScores); | ||
} | ||
} else { | ||
console.error(` Error: ${result.error}`); | ||
} | ||
} | ||
res.render("result.ejs", { result: results }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}); | ||
|
||
app.listen(process.env.PORT || 8000); |
Oops, something went wrong.