Stardragon2099 commited on
Commit
641b8ed
·
1 Parent(s): 12280e5

ported to chatgpt api

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -60,10 +60,9 @@ DEFAULT_PROMPT = ("You are a Leg Lift Classifier. There is an image of a through
60
 
61
  def predict(img, prompt):
62
  # Encode the Pillow image in base64
63
- buffer = BytesIO()
64
- img.save(buffer, format="PNG") # Save the image in PNG format (can change to JPEG if needed)
65
- buffer.seek(0)
66
- encoded_image = base64.b64encode(buffer.read()).decode('utf-8')
67
 
68
  # Combine prompt and image
69
  # system_prompt = (
@@ -73,14 +72,15 @@ def predict(img, prompt):
73
 
74
  messages = [
75
  {"role": "system", "content": prompt},
76
- {"role": "user", "content": f"Image (base64): {encoded_image}"}
77
  ]
78
 
79
  # Make API call
80
  try:
81
  response = openai.ChatCompletion.create(
82
- model="gpt-4",
83
- messages=messages
 
84
  )
85
  return response['choices'][0]['message']['content']
86
  except Exception as e:
 
60
 
61
  def predict(img, prompt):
62
  # Encode the Pillow image in base64
63
+ image_bytes = BytesIO()
64
+ img.save(image_bytes, format='PNG') # Save as PNG (can be changed to JPEG)
65
+ image_bytes.seek(0) # Rewind the BytesIO buffer
 
66
 
67
  # Combine prompt and image
68
  # system_prompt = (
 
72
 
73
  messages = [
74
  {"role": "system", "content": prompt},
75
+ {"role": "user", "content": f"Image (base64): {image_bytes}"}
76
  ]
77
 
78
  # Make API call
79
  try:
80
  response = openai.ChatCompletion.create(
81
+ model="gpt-4-vision",
82
+ messages=messages,
83
+ files=[("file", image_bytes)]
84
  )
85
  return response['choices'][0]['message']['content']
86
  except Exception as e: