Measterly commited on
Commit
2e0f573
·
verified ·
1 Parent(s): 482124c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -5,9 +5,9 @@ from PIL import Image
5
  import io
6
  import base64
7
 
8
- # Configure API (keeping DeepSeek variable names for simplicity)
9
- API_KEY = os.getenv("DEEPSEEK_API_KEY")
10
- API_ENDPOINT = "https://api.deepseek.com/v1/chat/completions" # Change if using OpenAI
11
 
12
  def encode_image(image):
13
  """Convert image to a base64 string for AI processing."""
@@ -17,11 +17,11 @@ def encode_image(image):
17
 
18
  def get_valuation(item_description, image_base64=None):
19
  """Generate an estimated value range based on past auction data."""
 
20
  if not API_KEY:
21
- st.error("API key is missing. Please set it in your Hugging Face secrets.")
22
  return None
23
 
24
- model = "gpt-4"
25
  prompt = f"""
26
  As a professional auctioneer and appraiser, estimate the value range for the following item based on past auction data:
27
 
@@ -39,7 +39,7 @@ def get_valuation(item_description, image_base64=None):
39
  }
40
 
41
  data = {
42
- "model": model,
43
  "messages": [
44
  {"role": "system", "content": "You are a seasoned auction expert specializing in item valuation and auction advisement."},
45
  {"role": "user", "content": prompt}
@@ -48,10 +48,9 @@ def get_valuation(item_description, image_base64=None):
48
  "max_tokens": 1000
49
  }
50
 
51
- # Use GPT-4 Vision if an image is provided
52
  if image_base64:
53
- model = "gpt-4-vision-preview"
54
- data["image"] = image_base64 # Ensure DeepSeek supports this
55
 
56
  try:
57
  response = requests.post(API_ENDPOINT, json=data, headers=headers)
@@ -83,7 +82,7 @@ elif input_method == "Upload an image":
83
  image = Image.open(uploaded_image)
84
  st.image(image, caption="Uploaded Image", use_column_width=True)
85
  description = st.text_area("(Optional) Add additional details about the item")
86
-
87
  # Convert image to RGB mode before saving as JPEG
88
  if image.mode == "RGBA":
89
  image = image.convert("RGB")
 
5
  import io
6
  import base64
7
 
8
+ # Configure API (use OpenAI or DeepSeek)
9
+ API_KEY = os.getenv("DEEPSEEK_API_KEY") # Change to "OPENAI_API_KEY" if using OpenAI
10
+ API_ENDPOINT = "https://api.openai.com/v1/chat/completions" # Adjust if using DeepSeek
11
 
12
  def encode_image(image):
13
  """Convert image to a base64 string for AI processing."""
 
17
 
18
  def get_valuation(item_description, image_base64=None):
19
  """Generate an estimated value range based on past auction data."""
20
+
21
  if not API_KEY:
22
+ st.error("API key is missing! Please set it in your Hugging Face secrets.")
23
  return None
24
 
 
25
  prompt = f"""
26
  As a professional auctioneer and appraiser, estimate the value range for the following item based on past auction data:
27
 
 
39
  }
40
 
41
  data = {
42
+ "model": "gpt-4",
43
  "messages": [
44
  {"role": "system", "content": "You are a seasoned auction expert specializing in item valuation and auction advisement."},
45
  {"role": "user", "content": prompt}
 
48
  "max_tokens": 1000
49
  }
50
 
51
+ # Ensure DeepSeek supports image inputs before using it
52
  if image_base64:
53
+ data["image"] = image_base64
 
54
 
55
  try:
56
  response = requests.post(API_ENDPOINT, json=data, headers=headers)
 
82
  image = Image.open(uploaded_image)
83
  st.image(image, caption="Uploaded Image", use_column_width=True)
84
  description = st.text_area("(Optional) Add additional details about the item")
85
+
86
  # Convert image to RGB mode before saving as JPEG
87
  if image.mode == "RGBA":
88
  image = image.convert("RGB")