Measterly commited on
Commit
5756e9f
·
verified ·
1 Parent(s): 814ef39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -30
app.py CHANGED
@@ -1,25 +1,11 @@
1
  import streamlit as st
2
  import requests
3
  import os
4
- from PIL import Image
5
- import io
6
- import base64
7
 
8
  # Configure OpenAI API
9
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
10
  OPENAI_ENDPOINT = "https://api.openai.com/v1/chat/completions"
11
 
12
- def encode_image(image):
13
- """Convert image to a base64 string for AI processing."""
14
- img_bytes = io.BytesIO()
15
-
16
- # Convert RGBA images to RGB before saving
17
- if image.mode != "RGB":
18
- image = image.convert("RGB")
19
-
20
- image.save(img_bytes, format="JPEG")
21
- return base64.b64encode(img_bytes.getvalue()).decode()
22
-
23
  def get_valuation(item_description):
24
  """Generate an estimated value range based on past auction data."""
25
  if not OPENAI_API_KEY:
@@ -61,22 +47,9 @@ def get_valuation(item_description):
61
  # Streamlit UI
62
  st.set_page_config(page_title="Auction Valuation Tool", layout="wide")
63
  st.title("📸 AI-Powered Auction Valuation")
64
- st.markdown("### Upload an image or describe an item to estimate its value")
65
-
66
- # User input options
67
- input_method = st.radio("Choose input method:", ["Describe the item", "Upload an image"])
68
-
69
- description = ""
70
-
71
- if input_method == "Describe the item":
72
- description = st.text_area("Describe the item in detail*")
73
 
74
- elif input_method == "Upload an image":
75
- uploaded_image = st.file_uploader("Upload an image of the item", type=["jpg", "png", "jpeg"])
76
- if uploaded_image:
77
- image = Image.open(uploaded_image)
78
- st.image(image, caption="Uploaded Image", use_column_width=True)
79
- description = st.text_area("(Optional) Add additional details about the item")
80
 
81
  if st.button("Get Estimated Value"):
82
  if not description:
@@ -85,4 +58,4 @@ if st.button("Get Estimated Value"):
85
  with st.spinner("Analyzing item and fetching valuation..."):
86
  valuation = get_valuation(description)
87
  if valuation:
88
- st.markdown(valuation)
 
1
  import streamlit as st
2
  import requests
3
  import os
 
 
 
4
 
5
  # Configure OpenAI API
6
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
7
  OPENAI_ENDPOINT = "https://api.openai.com/v1/chat/completions"
8
 
 
 
 
 
 
 
 
 
 
 
 
9
  def get_valuation(item_description):
10
  """Generate an estimated value range based on past auction data."""
11
  if not OPENAI_API_KEY:
 
47
  # Streamlit UI
48
  st.set_page_config(page_title="Auction Valuation Tool", layout="wide")
49
  st.title("📸 AI-Powered Auction Valuation")
50
+ st.markdown("### Describe an item to estimate its value")
 
 
 
 
 
 
 
 
51
 
52
+ description = st.text_area("Describe the item in detail*")
 
 
 
 
 
53
 
54
  if st.button("Get Estimated Value"):
55
  if not description:
 
58
  with st.spinner("Analyzing item and fetching valuation..."):
59
  valuation = get_valuation(description)
60
  if valuation:
61
+ st.markdown(valuation)