history008 commited on
Commit
bd270aa
·
verified ·
1 Parent(s): 5126217

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +49 -0
app.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const { exec } = require('child_process');
2
+ const { promises: fs } = require('fs');
3
+ const { GoogleGenerativeAI } = require('@google/generative-ai');
4
+
5
+ // --- WARNING: Do not put your API key directly in the code ---
6
+ // It is recommended to use environment variables for secrets.
7
+ // process.env.GEMINI_API_KEY should be set in Hugging Face secrets.
8
+ const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
9
+
10
+ async function summarizePage(url, task) {
11
+ return new Promise((resolve, reject) => {
12
+ // This command runs Skyvern to perform the task.
13
+ // The --task parameter defines what Skyvern should do.
14
+ const command = `skyvern run --url "${url}" --task "${task}"`;
15
+
16
+ exec(command, (err, stdout, stderr) => {
17
+ if (err) {
18
+ reject(`Skyvern CLI error: ${stderr}`);
19
+ return;
20
+ }
21
+ resolve(stdout);
22
+ });
23
+ });
24
+ }
25
+
26
+ async function main() {
27
+ const url = "https://www.example.com";
28
+ const task = "Summarize the key information on this page.";
29
+
30
+ try {
31
+ console.log(`Running Skyvern on: ${url}`);
32
+ const skyvernOutput = await summarizePage(url, task);
33
+
34
+ console.log("Skyvern output:", skyvernOutput);
35
+
36
+ // Now pass the output to the Gemini API for final summarization or analysis.
37
+ const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro" });
38
+ const result = await model.generateContent(skyvernOutput);
39
+ const response = await result.response;
40
+ const summary = response.text();
41
+
42
+ console.log("Final Summary from Gemini:", summary);
43
+
44
+ } catch (error) {
45
+ console.error("An error occurred:", error);
46
+ }
47
+ }
48
+
49
+ main();