cszhzleo commited on
Commit
859cc25
·
verified ·
1 Parent(s): 1c873bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -1,11 +1,24 @@
1
  import streamlit as st
2
- #from streamlit_datalist import stDatalist
3
  from utils import convert_to_base64, convert_to_html
4
  import requests
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- IP = '127.0.0.1'
7
- PORT= 8080
8
- url = f'http://{IP}:{PORT}/predictions/model'
9
  headers = {'Content-Type': 'application/json'}
10
  st.set_page_config(page_title="AWS Inferentia2 Demo", layout="wide")
11
  #st.set_page_config(layout="wide")
@@ -72,9 +85,15 @@ def ask_llm(prompt, byte_image):
72
  "temperature": 0.2,
73
  }
74
  }
75
- response = requests.post(url, json=payload, headers=headers)
 
 
 
 
 
76
 
77
- return response.text
 
78
 
79
  def app():
80
  st.markdown("---")
 
1
  import streamlit as st
 
2
  from utils import convert_to_base64, convert_to_html
3
  import requests
4
+ import boto3
5
+ import sagemaker
6
+
7
+ region = os.getenv("region")
8
+ sm_endpoint_name = os.getenv("sm_endpoint_name")
9
+ access_key = os.getenv("access_key")
10
+ secret_key = os.getenv("secret_key")
11
+ hf_token = os.getenv("hf_read_access")
12
+
13
+ session = boto3.Session(
14
+ aws_access_key_id=access_key,
15
+ aws_secret_access_key=secret_key,
16
+ region_name=region
17
+ )
18
+ sess = sagemaker.Session(boto_session=session)
19
+
20
+ smr = session.client("sagemaker-runtime")
21
 
 
 
 
22
  headers = {'Content-Type': 'application/json'}
23
  st.set_page_config(page_title="AWS Inferentia2 Demo", layout="wide")
24
  #st.set_page_config(layout="wide")
 
85
  "temperature": 0.2,
86
  }
87
  }
88
+ #response = requests.post(url, json=payload, headers=headers)
89
+ response = smr.invoke_endpoint(
90
+ EndpointName=sm_endpoint_name,
91
+ Body=json.dumps(payload),
92
+ ContentType="application/json",
93
+ )
94
 
95
+ #return response.text
96
+ return response
97
 
98
  def app():
99
  st.markdown("---")