Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,10 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Set page config
|
| 7 |
st.set_page_config(
|
|
@@ -90,6 +94,11 @@ if st.button("Summarize"):
|
|
| 90 |
if thread_url.strip():
|
| 91 |
with st.spinner("Analyzing thread..."):
|
| 92 |
# Build request payload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
payload = {
|
| 94 |
"inputs": [
|
| 95 |
{
|
|
@@ -98,7 +107,6 @@ if st.button("Summarize"):
|
|
| 98 |
"data": [thread_url],
|
| 99 |
"datatype": "BYTES"
|
| 100 |
},
|
| 101 |
-
# Optional parameters
|
| 102 |
{
|
| 103 |
"name": "temperature",
|
| 104 |
"optional": True,
|
|
@@ -110,14 +118,14 @@ if st.button("Summarize"):
|
|
| 110 |
"name": "top_p",
|
| 111 |
"optional": True,
|
| 112 |
"shape": [1],
|
| 113 |
-
"data": [1
|
| 114 |
"datatype": "FP64"
|
| 115 |
},
|
| 116 |
{
|
| 117 |
"name": "repetition_penalty",
|
| 118 |
"optional": True,
|
| 119 |
"shape": [1],
|
| 120 |
-
"data": [1
|
| 121 |
"datatype": "FP64"
|
| 122 |
},
|
| 123 |
{
|
|
@@ -144,13 +152,12 @@ if st.button("Summarize"):
|
|
| 144 |
]
|
| 145 |
}
|
| 146 |
|
|
|
|
|
|
|
|
|
|
| 147 |
try:
|
| 148 |
# Send POST request to your local model server
|
| 149 |
-
response = requests.post(
|
| 150 |
-
"http://localhost:8000/v2/models/inferless-model/infer",
|
| 151 |
-
json=payload,
|
| 152 |
-
timeout=30
|
| 153 |
-
)
|
| 154 |
response.raise_for_status() # Raise HTTPError if status != 200
|
| 155 |
|
| 156 |
# Parse JSON response
|
|
@@ -164,4 +171,4 @@ if st.button("Summarize"):
|
|
| 164 |
except requests.exceptions.RequestException as e:
|
| 165 |
st.error(f"Error calling the model API: {e}")
|
| 166 |
else:
|
| 167 |
-
st.error("Please enter a valid URL.")
|
|
|
|
| 2 |
import requests
|
| 3 |
import json
|
| 4 |
import time
|
| 5 |
+
import os
|
| 6 |
+
api_url = os.getenv("API_URL")
|
| 7 |
+
auth_token = os.getenv("AUTH_TOKEN")
|
| 8 |
+
|
| 9 |
|
| 10 |
# Set page config
|
| 11 |
st.set_page_config(
|
|
|
|
| 94 |
if thread_url.strip():
|
| 95 |
with st.spinner("Analyzing thread..."):
|
| 96 |
# Build request payload
|
| 97 |
+
headers = {
|
| 98 |
+
'Content-Type': 'application/json',
|
| 99 |
+
'Authorization': f'Bearer {auth_token}'
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
payload = {
|
| 103 |
"inputs": [
|
| 104 |
{
|
|
|
|
| 107 |
"data": [thread_url],
|
| 108 |
"datatype": "BYTES"
|
| 109 |
},
|
|
|
|
| 110 |
{
|
| 111 |
"name": "temperature",
|
| 112 |
"optional": True,
|
|
|
|
| 118 |
"name": "top_p",
|
| 119 |
"optional": True,
|
| 120 |
"shape": [1],
|
| 121 |
+
"data": [1],
|
| 122 |
"datatype": "FP64"
|
| 123 |
},
|
| 124 |
{
|
| 125 |
"name": "repetition_penalty",
|
| 126 |
"optional": True,
|
| 127 |
"shape": [1],
|
| 128 |
+
"data": [1],
|
| 129 |
"datatype": "FP64"
|
| 130 |
},
|
| 131 |
{
|
|
|
|
| 152 |
]
|
| 153 |
}
|
| 154 |
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
|
| 158 |
try:
|
| 159 |
# Send POST request to your local model server
|
| 160 |
+
response = requests.post(api_url, headers=headers, json=payload,timeout=30)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
response.raise_for_status() # Raise HTTPError if status != 200
|
| 162 |
|
| 163 |
# Parse JSON response
|
|
|
|
| 171 |
except requests.exceptions.RequestException as e:
|
| 172 |
st.error(f"Error calling the model API: {e}")
|
| 173 |
else:
|
| 174 |
+
st.error("Please enter a valid URL.")
|