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( """ """, unsafe_allow_html=True ) # Main header: Product Hunt Thread Summarizer with Product Hunt icon st.markdown( """
Product Hunt Logo

Product Hunt Thread Summarizer

""", unsafe_allow_html=True ) # Powered by Inferless banner (without border) st.markdown( """
Inferless Logo
Powered by Inferless
""", 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.")