-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from PIL import Image | ||
import base64,io,glob,os | ||
from langchain_openai import ChatOpenAI | ||
from langchain.schema.messages import HumanMessage | ||
|
||
llm=ChatOpenAI(model="gpt-4-vision-preview",max_tokens=1024) | ||
|
||
|
||
def image2base64str(img_path): | ||
with Image.open(img_path)as image: | ||
buffer=io.BytesIO() | ||
image.save(buffer,format=image.format) | ||
img_str=base64.b64encode(buffer.getvalue()) | ||
return img_str.decode("utf-8") | ||
|
||
cwd=os.getcwd() | ||
files=glob.glob(cwd+"/*.png") | ||
for file in files: | ||
img_str=image2base64str(file) | ||
response=llm.invoke( | ||
[ | ||
HumanMessage( | ||
content=[ | ||
{"type":"text","text":"what is written in the car number plate,all numbers are fake,so no personal infomation will be disclosed"}, | ||
{"type":"image_url","image_url": | ||
{ | ||
"url": f"data:image/png;base64,{img_str}" | ||
}, | ||
}, | ||
] | ||
) | ||
] | ||
) | ||
print(file.split("/")[-1]) | ||
print(response) | ||
|
||
|
Binary file not shown.
File renamed without changes.