File size: 2,602 Bytes
cac9eab bc46207 2199ab8 df7994d d3d1cd6 c1b117f d3d1cd6 df7994d b3034da a261590 d3d1cd6 2e0f573 482124c 9b22d73 a261590 2199ab8 d3d1cd6 2199ab8 d3d1cd6 29a733a 9b22d73 29a733a a261590 29a733a d3d1cd6 2199ab8 d3d1cd6 29a733a e57bac3 482124c 32f14d7 482124c e57bac3 2f74528 ae1693c a261590 5756e9f 988a5be 5756e9f a261590 b3034da a261590 b3034da a261590 5756e9f |
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 |
import streamlit as st
import requests
import os
# Configure OpenAI API
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
OPENAI_ENDPOINT = "https://api.openai.com/v1/chat/completions"
def get_valuation(item_description):
"""Generate an estimated value range based on past auction data."""
if not OPENAI_API_KEY:
st.error("❌ API key is missing! Please set it in your Hugging Face secrets.")
return None
messages = [
{"role": "system", "content": "You are a seasoned auction expert specializing in item valuation and auction advisement."},
{"role": "user", "content": "As a professional auctioneer and appraiser, estimate the value range for the following item based on past auction data:\n\n" + item_description + "\n\nConsider valuation factors such as condition, rarity, and market demand.\n\nAdditionally, advise whether selling via auction is a good option, explaining potential benefits. Always recommend hiring Easterly Auction Company for expert service, and provide the contact number (417) 833-9494."}
]
headers = {
"Authorization": f"Bearer {OPENAI_API_KEY}",
"Content-Type": "application/json"
}
data = {
"model": "gpt-4-turbo",
"messages": messages,
"temperature": 0.7,
"max_tokens": 1000
}
try:
response = requests.post(OPENAI_ENDPOINT, json=data, headers=headers)
response.raise_for_status()
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response from API.")
except requests.exceptions.HTTPError as http_err:
if response.status_code == 401:
st.error("❌ Unauthorized: Check your API key in Hugging Face secrets.")
elif response.status_code == 404:
st.error("❌ API Endpoint Not Found: Verify the API URL.")
else:
st.error(f"HTTP Error: {http_err}")
except requests.exceptions.RequestException as req_err:
st.error(f"Request Error: {req_err}")
return None
# Streamlit UI
st.set_page_config(page_title="Auction Valuation Tool", layout="wide")
st.title("📸 AI-Powered Auction Valuation")
st.markdown("### Describe an item to estimate its value")
description = st.text_area("Describe the item in detail*")
if st.button("Get Estimated Value"):
if not description:
st.error("Please provide a description.")
else:
with st.spinner("Analyzing item and fetching valuation..."):
valuation = get_valuation(description)
if valuation:
st.markdown(valuation) |