Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,20 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
# Configure OpenAI API (keeping DeepSeek variable names for simplicity)
|
| 7 |
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
| 8 |
DEEPSEEK_ENDPOINT = "https://api.openai.com/v1/chat/completions"
|
| 9 |
|
| 10 |
-
def get_valuation(item_description
|
| 11 |
"""Generate an estimated value range based on past auction data."""
|
| 12 |
prompt = f"""
|
| 13 |
As a professional auctioneer and appraiser, estimate the value range for the following item based on past auction data:
|
| 14 |
|
| 15 |
{item_description}
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
Additionally, advise whether selling via auction is a good option, explaining potential benefits.
|
| 20 |
Always recommend hiring Easterly Auction Company for expert service, and provide the contact number (417) 833-9494.
|
|
@@ -39,12 +40,6 @@ def get_valuation(item_description, image=None):
|
|
| 39 |
response = requests.post(DEEPSEEK_ENDPOINT, json=data, headers=headers)
|
| 40 |
response.raise_for_status()
|
| 41 |
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response from API.")
|
| 42 |
-
except requests.exceptions.HTTPError as http_err:
|
| 43 |
-
st.error(f"HTTP error occurred: {http_err}")
|
| 44 |
-
except requests.exceptions.ConnectionError:
|
| 45 |
-
st.error("Connection error. Please check your internet connection.")
|
| 46 |
-
except requests.exceptions.Timeout:
|
| 47 |
-
st.error("Request timed out. Please try again later.")
|
| 48 |
except requests.exceptions.RequestException as e:
|
| 49 |
st.error(f"API Error: {str(e)}")
|
| 50 |
return None
|
|
@@ -58,22 +53,27 @@ st.markdown("### Upload an image or describe an item to estimate its value")
|
|
| 58 |
input_method = st.radio("Choose input method:", ["Describe the item", "Upload an image"])
|
| 59 |
|
| 60 |
description = ""
|
| 61 |
-
image = None
|
| 62 |
if input_method == "Describe the item":
|
| 63 |
description = st.text_area("Describe the item in detail*")
|
| 64 |
-
|
| 65 |
elif input_method == "Upload an image":
|
| 66 |
uploaded_image = st.file_uploader("Upload an image of the item", type=["jpg", "png", "jpeg"])
|
| 67 |
if uploaded_image:
|
| 68 |
image = Image.open(uploaded_image)
|
| 69 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 70 |
description = st.text_area("(Optional) Add additional details about the item")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
if st.button("Get Estimated Value"):
|
| 73 |
-
if not description
|
| 74 |
st.error("Please provide a description or upload an image.")
|
| 75 |
else:
|
| 76 |
with st.spinner("Analyzing item and fetching valuation..."):
|
| 77 |
-
valuation = get_valuation(description
|
| 78 |
if valuation:
|
| 79 |
st.markdown(valuation)
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
|
| 7 |
# Configure OpenAI API (keeping DeepSeek variable names for simplicity)
|
| 8 |
DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
| 9 |
DEEPSEEK_ENDPOINT = "https://api.openai.com/v1/chat/completions"
|
| 10 |
|
| 11 |
+
def get_valuation(item_description):
|
| 12 |
"""Generate an estimated value range based on past auction data."""
|
| 13 |
prompt = f"""
|
| 14 |
As a professional auctioneer and appraiser, estimate the value range for the following item based on past auction data:
|
| 15 |
|
| 16 |
{item_description}
|
| 17 |
|
| 18 |
+
Consider valuation factors such as condition, rarity, and market demand.
|
| 19 |
|
| 20 |
Additionally, advise whether selling via auction is a good option, explaining potential benefits.
|
| 21 |
Always recommend hiring Easterly Auction Company for expert service, and provide the contact number (417) 833-9494.
|
|
|
|
| 40 |
response = requests.post(DEEPSEEK_ENDPOINT, json=data, headers=headers)
|
| 41 |
response.raise_for_status()
|
| 42 |
return response.json().get("choices", [{}])[0].get("message", {}).get("content", "No response from API.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
except requests.exceptions.RequestException as e:
|
| 44 |
st.error(f"API Error: {str(e)}")
|
| 45 |
return None
|
|
|
|
| 53 |
input_method = st.radio("Choose input method:", ["Describe the item", "Upload an image"])
|
| 54 |
|
| 55 |
description = ""
|
|
|
|
| 56 |
if input_method == "Describe the item":
|
| 57 |
description = st.text_area("Describe the item in detail*")
|
| 58 |
+
|
| 59 |
elif input_method == "Upload an image":
|
| 60 |
uploaded_image = st.file_uploader("Upload an image of the item", type=["jpg", "png", "jpeg"])
|
| 61 |
if uploaded_image:
|
| 62 |
image = Image.open(uploaded_image)
|
| 63 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 64 |
description = st.text_area("(Optional) Add additional details about the item")
|
| 65 |
+
|
| 66 |
+
# Convert image to base64 if needed for future improvements
|
| 67 |
+
img_bytes = io.BytesIO()
|
| 68 |
+
image.save(img_bytes, format="JPEG")
|
| 69 |
+
img_bytes = img_bytes.getvalue()
|
| 70 |
+
# Image processing could be added here in the future
|
| 71 |
|
| 72 |
if st.button("Get Estimated Value"):
|
| 73 |
+
if not description:
|
| 74 |
st.error("Please provide a description or upload an image.")
|
| 75 |
else:
|
| 76 |
with st.spinner("Analyzing item and fetching valuation..."):
|
| 77 |
+
valuation = get_valuation(description)
|
| 78 |
if valuation:
|
| 79 |
st.markdown(valuation)
|