Update app.py
Browse files
app.py
CHANGED
@@ -21,33 +21,38 @@ sys_prompt = read('system_prompt.txt')
|
|
21 |
|
22 |
def process_text(text_input, unit):
|
23 |
if text_input:
|
24 |
-
|
25 |
model=MODEL,
|
26 |
messages=[
|
27 |
{"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
|
28 |
{"role": "user", "content": f"Hello! Could you solve {text_input}?"}
|
29 |
]
|
30 |
)
|
31 |
-
return
|
|
|
|
|
32 |
|
33 |
-
def process_image(image_input,unit):
|
34 |
if image_input is not None:
|
35 |
with open(image_input.name, "rb") as f:
|
36 |
base64_image = base64.b64encode(f.read()).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
response = client.chat.completions.create(
|
38 |
model=MODEL,
|
39 |
-
messages=
|
40 |
-
{"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
|
41 |
-
{"role": "user", "content": [
|
42 |
-
{"type": "text", "text": "Help me understand what this image"},
|
43 |
-
{"type": "image_url", "image_url": {
|
44 |
-
"url": f"data:image/png;base64,{base64_image}"}
|
45 |
-
}
|
46 |
-
]}
|
47 |
-
],
|
48 |
temperature=0.0,
|
49 |
)
|
50 |
return response.choices[0].message.content
|
|
|
|
|
51 |
|
52 |
def main(text_input="", image_input=None, unit=""):
|
53 |
if text_input and image_input is None:
|
|
|
21 |
|
22 |
def process_text(text_input, unit):
|
23 |
if text_input:
|
24 |
+
completion = client.chat.completions.create(
|
25 |
model=MODEL,
|
26 |
messages=[
|
27 |
{"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
|
28 |
{"role": "user", "content": f"Hello! Could you solve {text_input}?"}
|
29 |
]
|
30 |
)
|
31 |
+
return completion.choices[0].message.content
|
32 |
+
return ""
|
33 |
+
|
34 |
|
35 |
+
def process_image(image_input, unit):
|
36 |
if image_input is not None:
|
37 |
with open(image_input.name, "rb") as f:
|
38 |
base64_image = base64.b64encode(f.read()).decode("utf-8")
|
39 |
+
messages = [
|
40 |
+
{"role": "system", "content": f" You are a helpful {unit} doctor." + sys_prompt},
|
41 |
+
{"role": "user", "content": [
|
42 |
+
{"type": "text", "text": "Help me understand what this image"},
|
43 |
+
{"type": "image_url", "image_url": {
|
44 |
+
"url": f"data:image/png;base64,{base64_image}"}
|
45 |
+
}
|
46 |
+
]}
|
47 |
+
]
|
48 |
response = client.chat.completions.create(
|
49 |
model=MODEL,
|
50 |
+
messages=messages,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
temperature=0.0,
|
52 |
)
|
53 |
return response.choices[0].message.content
|
54 |
+
return ""
|
55 |
+
|
56 |
|
57 |
def main(text_input="", image_input=None, unit=""):
|
58 |
if text_input and image_input is None:
|