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