coyotte508 HF Staff commited on
Commit
658bf45
·
1 Parent(s): 9920173

✨ Got the alt text

Browse files
Files changed (1) hide show
  1. server.ts +17 -3
server.ts CHANGED
@@ -89,9 +89,23 @@ async function lookupTweets() {
89
 
90
  console.log("imageUrl", imageUrl);
91
 
92
- const image = await (await fetch(imageUrl)).arrayBuffer();
93
-
94
- console.log(image);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  }
96
 
97
  async function listen() {
 
89
 
90
  console.log("imageUrl", imageUrl);
91
 
92
+ const imageResp = await fetch(imageUrl);
93
+ const contentType = imageResp.headers.get("Content-Type");
94
+ const image = await imageResp.arrayBuffer();
95
+
96
+ console.log(contentType, image);
97
+
98
+ const altText = await fetch("https://olivierdehaene-git-large-coco.hf.space/run/predict", {
99
+ method: "POST",
100
+ headers: { "Content-Type": "application/json" },
101
+ body: JSON.stringify({
102
+ data: [`data:${contentType};base64,${Buffer.from(image).toString("base64")}`],
103
+ }),
104
+ })
105
+ .then((r) => r.json())
106
+ .then((r) => r.data);
107
+
108
+ console.log(altText);
109
  }
110
 
111
  async function listen() {