Update app.py
Browse files
app.py
CHANGED
@@ -32,23 +32,32 @@ def process_text(text_input, unit):
|
|
32 |
return completion.choices[0].message.content
|
33 |
return ""
|
34 |
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def process_image(image_input, unit):
|
37 |
if image_input is not None:
|
38 |
-
with open(image_input.name, "rb") as f:
|
39 |
-
|
|
|
40 |
response = client.chat.completions.create(
|
41 |
model=MODEL,
|
42 |
messages=[
|
43 |
{"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
|
44 |
{"role": "user", "content": [
|
45 |
{"type": "text", "text": "Help me understand what this image"},
|
46 |
-
{"type": "image_url",
|
47 |
-
|
|
|
|
|
48 |
}
|
49 |
]}
|
50 |
],
|
51 |
temperature=0.0,
|
|
|
52 |
)
|
53 |
print(response)
|
54 |
return response.choices[0].message.content
|
|
|
32 |
return completion.choices[0].message.content
|
33 |
return ""
|
34 |
|
35 |
+
def encode_image_to_base64(image):
|
36 |
+
buffered = io.BytesIO()
|
37 |
+
image.save(buffered, format="JPEG")
|
38 |
+
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
39 |
+
return img_str
|
40 |
|
41 |
def process_image(image_input, unit):
|
42 |
if image_input is not None:
|
43 |
+
#with open(image_input.name, "rb") as f:
|
44 |
+
# base64_image = base64.b64encode(f.read()).decode("utf-8")
|
45 |
+
base64_image = encode_image_to_base64(image)
|
46 |
response = client.chat.completions.create(
|
47 |
model=MODEL,
|
48 |
messages=[
|
49 |
{"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
|
50 |
{"role": "user", "content": [
|
51 |
{"type": "text", "text": "Help me understand what this image"},
|
52 |
+
{"type": "image_url",
|
53 |
+
"image_url": {
|
54 |
+
"url": f"data:image/jpeg;base64,{base64_image}",
|
55 |
+
"detail":"low"}
|
56 |
}
|
57 |
]}
|
58 |
],
|
59 |
temperature=0.0,
|
60 |
+
max_tokens=1024,
|
61 |
)
|
62 |
print(response)
|
63 |
return response.choices[0].message.content
|