fixed api issues
Browse files
app.py
CHANGED
@@ -7,9 +7,9 @@ import json
|
|
7 |
if "stream" not in st.session_state:
|
8 |
st.session_state.stream = True
|
9 |
|
10 |
-
api_key = os.getenv("
|
11 |
-
MODEL_ID = "llama-3.2-
|
12 |
-
invoke_url = "https://ai.api.nvidia.com/v1/gr/meta/llama-3.2-
|
13 |
|
14 |
# Function to encode the image
|
15 |
def encode_image(image_path):
|
@@ -107,17 +107,6 @@ def main():
|
|
107 |
stream=stream # Important for streaming
|
108 |
)
|
109 |
|
110 |
-
#handle if the AI refused to connect
|
111 |
-
try:
|
112 |
-
if (
|
113 |
-
json.loads(response).get("type") == "about:blank"
|
114 |
-
and json.loads(response).get("status") == 404):
|
115 |
-
st.error("Resource not found. Please check the URL.")
|
116 |
-
return
|
117 |
-
except json.JSONDecodeError as e:
|
118 |
-
st.error("Resource not found. Please check the URL.")
|
119 |
-
pass
|
120 |
-
|
121 |
if stream:
|
122 |
print(f"response: {response.text}")
|
123 |
|
@@ -126,6 +115,8 @@ def main():
|
|
126 |
# Efficiently handle streaming response
|
127 |
for chunk in response.iter_lines():
|
128 |
|
|
|
|
|
129 |
if len(chunk) > 0:
|
130 |
content += extract_content(chunk)
|
131 |
response_container.markdown(content)
|
|
|
7 |
if "stream" not in st.session_state:
|
8 |
st.session_state.stream = True
|
9 |
|
10 |
+
api_key = os.getenv("NVIDIA_VISION_API_KEY")
|
11 |
+
MODEL_ID = "meta/llama-3.2-90b-vision-instruct"
|
12 |
+
invoke_url = "https://ai.api.nvidia.com/v1/gr/meta/llama-3.2-90b-vision-instruct/chat/completions"
|
13 |
|
14 |
# Function to encode the image
|
15 |
def encode_image(image_path):
|
|
|
107 |
stream=stream # Important for streaming
|
108 |
)
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
if stream:
|
111 |
print(f"response: {response.text}")
|
112 |
|
|
|
115 |
# Efficiently handle streaming response
|
116 |
for chunk in response.iter_lines():
|
117 |
|
118 |
+
print(f"chunk: {chunk}")
|
119 |
+
|
120 |
if len(chunk) > 0:
|
121 |
content += extract_content(chunk)
|
122 |
response_container.markdown(content)
|