|
import streamlit as st |
|
import requests |
|
import json |
|
import time |
|
import os |
|
api_url = os.getenv("API_URL") |
|
auth_token = os.getenv("AUTH_TOKEN") |
|
|
|
|
|
|
|
st.set_page_config( |
|
page_title="Product Hunt Thread Summarizer", |
|
layout="wide", |
|
initial_sidebar_state="collapsed" |
|
) |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
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 |
|
) |
|
|
|
|
|
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" |
|
) |
|
|
|
|
|
if st.button("Summarize"): |
|
if thread_url.strip(): |
|
with st.spinner("Analyzing thread..."): |
|
|
|
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: |
|
|
|
response = requests.post(api_url, headers=headers, json=payload,timeout=300) |
|
response.raise_for_status() |
|
|
|
|
|
data = response.json() |
|
summary_text = data["outputs"][0]["data"][0] |
|
|
|
|
|
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.") |