File size: 5,139 Bytes
25ab3a2 18524d5 25ab3a2 18524d5 25ab3a2 18524d5 25ab3a2 18524d5 25ab3a2 18524d5 25ab3a2 93a1b8c 25ab3a2 18524d5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
import streamlit as st
import requests
import json
import time
import os
api_url = os.getenv("API_URL")
auth_token = os.getenv("AUTH_TOKEN")
# Set page config
st.set_page_config(
page_title="Product Hunt Thread Summarizer",
layout="wide",
initial_sidebar_state="collapsed"
)
# Custom CSS for header and banners
st.markdown(
"""
<style>
/* Main header with Product Hunt icon */
#main-header {
display: flex;
align-items: center;
margin-bottom: 10px;
}
#main-header img {
width: 50px;
height: 50px;
margin-right: 15px;
border-radius: 4px;
}
#main-header h1 {
font-size: 32px;
margin: 0;
color: #333;
}
/* Inferless banner without border */
#inferless-banner {
display: flex;
align-items: center;
background-color: #ffffff;
padding: 10px 15px;
margin-bottom: 20px;
border-radius: 8px;
}
#inferless-banner img {
width: 40px;
height: 40px;
margin-right: 10px;
border-radius: 4px;
}
#inferless-banner .inferless-text {
font-size: 18px;
font-weight: 600;
color: #333;
}
</style>
""",
unsafe_allow_html=True
)
# Main header: Product Hunt Thread Summarizer with Product Hunt icon
st.markdown(
"""
<div id="main-header">
<img src="https://i.tracxn.com/logo/company/588f54924f2a60b6aae128ac436d95a4?format=webp&height=120&width=120" alt="Product Hunt Logo">
<h1>Product Hunt Thread Summarizer</h1>
</div>
""",
unsafe_allow_html=True
)
# Powered by Inferless banner (without border)
st.markdown(
"""
<div id="inferless-banner">
<img src="https://i.tracxn.com/logo/company/1678863153264_9e6a9a4d-b955-42b3-895e-b94ade13c997.jpeg?format=webp&height=120&width=120" alt="Inferless Logo">
<div class="inferless-text">Powered by Inferless</div>
</div>
""",
unsafe_allow_html=True
)
# Input field for thread URL
thread_url = st.text_input(
label="Enter URL",
placeholder="https://www.producthunt.com/p/graphite/you-re-doing-code-reviews-wrong-ama-w-ceo-of-graphite",
help="Paste the URL you want to summarize"
)
# Button to call your local inference API
if st.button("Summarize"):
if thread_url.strip():
with st.spinner("Analyzing thread..."):
# Build request payload
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {auth_token}'
}
payload = {
"inputs": [
{
"name": "url",
"shape": [1],
"data": [thread_url],
"datatype": "BYTES"
},
{
"name": "temperature",
"optional": True,
"shape": [1],
"data": [0.15],
"datatype": "FP64"
},
{
"name": "top_p",
"optional": True,
"shape": [1],
"data": [1],
"datatype": "FP64"
},
{
"name": "repetition_penalty",
"optional": True,
"shape": [1],
"data": [1],
"datatype": "FP64"
},
{
"name": "top_k",
"optional": True,
"shape": [1],
"data": [-1],
"datatype": "INT32"
},
{
"name": "max_tokens",
"optional": True,
"shape": [1],
"data": [1024],
"datatype": "INT32"
},
{
"name": "seed",
"optional": True,
"shape": [1],
"data": [4424234],
"datatype": "INT32"
}
]
}
try:
# Send POST request to your local model server
response = requests.post(api_url, headers=headers, json=payload,timeout=300)
response.raise_for_status() # Raise HTTPError if status != 200
# Parse JSON response
data = response.json()
summary_text = data["outputs"][0]["data"][0]
# Display the result in Streamlit
st.markdown("### Summary")
st.write(summary_text)
except requests.exceptions.RequestException as e:
st.error(f"Error calling the model API: {e}")
else:
st.error("Please enter a valid URL.") |