Measterly commited on
Commit
b3034da
·
verified ·
1 Parent(s): 9b22d73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -20,7 +20,7 @@ def encode_image(image):
20
  image.save(img_bytes, format="JPEG")
21
  return base64.b64encode(img_bytes.getvalue()).decode()
22
 
23
- def get_valuation(item_description, image=None):
24
  """Generate an estimated value range based on past auction data."""
25
  if not OPENAI_API_KEY:
26
  st.error("❌ API key is missing! Please set it in your Hugging Face secrets.")
@@ -31,9 +31,6 @@ def get_valuation(item_description, image=None):
31
  {"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."}
32
  ]
33
 
34
- if image:
35
- messages.append({"role": "user", "content": {"type": "image_url", "image_url": image}})
36
-
37
  headers = {
38
  "Authorization": f"Bearer {OPENAI_API_KEY}",
39
  "Content-Type": "application/json"
@@ -70,7 +67,6 @@ st.markdown("### Upload an image or describe an item to estimate its value")
70
  input_method = st.radio("Choose input method:", ["Describe the item", "Upload an image"])
71
 
72
  description = ""
73
- image_url = None
74
 
75
  if input_method == "Describe the item":
76
  description = st.text_area("Describe the item in detail*")
@@ -81,17 +77,12 @@ elif input_method == "Upload an image":
81
  image = Image.open(uploaded_image)
82
  st.image(image, caption="Uploaded Image", use_column_width=True)
83
  description = st.text_area("(Optional) Add additional details about the item")
84
-
85
- # Save image to a temporary file and generate a URL
86
- image_path = f"temp_{uploaded_image.name}"
87
- image.save(image_path)
88
- image_url = f"file://{image_path}" # Simulating an image URL for OpenAI Vision model
89
 
90
  if st.button("Get Estimated Value"):
91
- if not description and not image_url:
92
- st.error("Please provide a description or upload an image.")
93
  else:
94
  with st.spinner("Analyzing item and fetching valuation..."):
95
- valuation = get_valuation(description, image_url)
96
  if valuation:
97
- st.markdown(valuation)
 
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:
26
  st.error("❌ API key is missing! Please set it in your Hugging Face secrets.")
 
31
  {"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."}
32
  ]
33
 
 
 
 
34
  headers = {
35
  "Authorization": f"Bearer {OPENAI_API_KEY}",
36
  "Content-Type": "application/json"
 
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*")
 
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:
83
+ st.error("Please provide a description.")
84
  else:
85
  with st.spinner("Analyzing item and fetching valuation..."):
86
+ valuation = get_valuation(description)
87
  if valuation:
88
+ st.markdown(valuation)