eagle0504 commited on
Commit
9fb9ed2
·
verified ·
1 Parent(s): b9fe198

Create helper.py

Browse files
Files changed (1) hide show
  1. helper.py +31 -0
helper.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import base64
4
+
5
+ # API endpoint
6
+ API_URL = "https://82le1lsl6e.execute-api.us-east-1.amazonaws.com/dev/test_bedrock_v5"
7
+
8
+ # Request payload (text+image)
9
+ image_path = "/content/test.png" # Replace with actual image path
10
+ with open(image_path, "rb") as image_file:
11
+ base64_image = base64.b64encode(image_file.read()).decode("utf-8")
12
+
13
+ payload = {
14
+ "image": base64_image,
15
+ "prompt": "Read the text in the image and summarize it.",
16
+ "max_tokens": 1000,
17
+ "temperature": 0.8,
18
+ "top_k": 150,
19
+ "top_p": 0.98
20
+ }
21
+
22
+ headers = {"Content-Type": "application/json"}
23
+
24
+ # Send request (fixed body format)
25
+ response = requests.post(API_URL, json=payload, headers=headers)
26
+ answer = response.json().get("model_response").get("content")[0].get("text")
27
+
28
+ # Print response
29
+ print("Status Code:", response.status_code)
30
+ print("Response:", response.json())
31
+ print("Answer:", answer)