Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1620,13 +1620,49 @@ def process_image_old_05152024(image_input):
|
|
1620 |
)
|
1621 |
st.markdown(response.choices[0].message.content)
|
1622 |
|
1623 |
-
def save_image(image_input,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1624 |
# Save the uploaded video file
|
1625 |
with open(filename_txt, "wb") as f:
|
1626 |
f.write(image_input.getbuffer())
|
1627 |
return image_input.name
|
1628 |
|
1629 |
-
def
|
1630 |
if image_input:
|
1631 |
base64_image = base64.b64encode(image_input.read()).decode("utf-8")
|
1632 |
response = client.chat.completions.create(
|
|
|
1620 |
)
|
1621 |
st.markdown(response.choices[0].message.content)
|
1622 |
|
1623 |
+
def save_image(image_input, filename):
|
1624 |
+
# Save the uploaded image file
|
1625 |
+
with open(filename, "wb") as f:
|
1626 |
+
f.write(image_input.getvalue())
|
1627 |
+
return filename
|
1628 |
+
|
1629 |
+
def process_image(image_input):
|
1630 |
+
if image_input:
|
1631 |
+
base64_image = base64.b64encode(image_input.read()).decode("utf-8")
|
1632 |
+
response = client.chat.completions.create(
|
1633 |
+
model=MODEL,
|
1634 |
+
messages=[
|
1635 |
+
{"role": "system", "content": "You are a helpful assistant that responds in Markdown."},
|
1636 |
+
{"role": "user", "content": [
|
1637 |
+
{"type": "text", "text": "Help me understand what is in this picture and list ten facts as markdown outline with appropriate emojis that describes what you see."},
|
1638 |
+
{"type": "image_url", "image_url": {
|
1639 |
+
"url": f"data:image/png;base64,{base64_image}"}
|
1640 |
+
}
|
1641 |
+
]}
|
1642 |
+
],
|
1643 |
+
temperature=0.0,
|
1644 |
+
)
|
1645 |
+
image_response = response.choices[0].message.content
|
1646 |
+
st.markdown(image_response)
|
1647 |
+
|
1648 |
+
# Save markdown on image AI output from gpt4o
|
1649 |
+
filename_md = f"{image_input.name}.md"
|
1650 |
+
with open(filename_md, "w", encoding="utf-8") as f:
|
1651 |
+
f.write(image_response)
|
1652 |
+
|
1653 |
+
# Save copy of image with original filename
|
1654 |
+
filename_img = image_input.name
|
1655 |
+
save_image(image_input, filename_img)
|
1656 |
+
|
1657 |
+
return image_response
|
1658 |
+
|
1659 |
+
def save_imageold(image_input, filename_txt):
|
1660 |
# Save the uploaded video file
|
1661 |
with open(filename_txt, "wb") as f:
|
1662 |
f.write(image_input.getbuffer())
|
1663 |
return image_input.name
|
1664 |
|
1665 |
+
def process_imageold(image_input):
|
1666 |
if image_input:
|
1667 |
base64_image = base64.b64encode(image_input.read()).decode("utf-8")
|
1668 |
response = client.chat.completions.create(
|