Skip to content

Instantly share code, notes, and snippets.

@tspannhw
Created October 26, 2024 17:25
Show Gist options
  • Select an option

  • Save tspannhw/1c2220e759436055e388246577f78b08 to your computer and use it in GitHub Desktop.

Select an option

Save tspannhw/1c2220e759436055e388246577f78b08 to your computer and use it in GitHub Desktop.
import requests
import base64
import ollama
from PIL import Image
from IPython.display import display
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
### Turn off slack warnings
os.environ["SKIP_SLACK_SDK_WARNING"] = "false"
slack_token = os.environ.get("SLACK_BOT_TOKEN")
client = WebClient(token=slack_token)
# notebook fragment
# MINICPM
# https://github.com/OpenBMB/MiniCPM-V
# https://github.com/OpenBMB/MiniCPM-V/raw/main/assets/minicpmv.png
# ollama run minicpm-v
# Model Name inicpm-v:latest
milvusimage = "/Users/timothyspann/Desktop/milvusdetails.png"
img = Image.open(milvusimage)
img = img.resize((640, 480))
display(img)
response = ollama.chat(model="minicpm-v:latest",messages=[{'role': 'user','content':
'(English Translation) Extract all text from this image.:',
'images': [str(milvusimage)]}])
responsetext = str( response['message']['content'] )
print( responsetext )
try:
slackresponse = str(responsetext).replace("**","*")
slackresponse = client.chat_postMessage(mrkdwn=True, channel="C06NE1FU6SE", text="",
blocks=[{"type": "section","text": {"type": "mrkdwn","text": str(slackresponse) +"\n" }}])
except SlackApiError as e:
print("Slack failed")
try:
response = client.files_upload_v2(
channel="C06NE1FU6SE",
file=milvusimage,
title="Milvus",
initial_comment="Milvus",
)
except SlackApiError as e:
assert e.response["error"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment