Instructions to use manh08/blip-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use manh08/blip-model with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="manh08/blip-model")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("manh08/blip-model", dtype="auto") - Notebooks
- Google Colab
- Kaggle
upload test_part1.py
Browse files- test_part1.py +28 -0
test_part1.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import find_dotenv, load_dotenv
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
# from langchain import PromptTemplate, LLMChain, OpenAI
|
| 4 |
+
from langchain_openai import ChatOpenAI
|
| 5 |
+
from langchain.prompts import PromptTemplate
|
| 6 |
+
from langchain.chains import LLMChain
|
| 7 |
+
from langchain_openai import ChatOpenAI
|
| 8 |
+
import requests
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
load_dotenv(find_dotenv())
|
| 12 |
+
# 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 = os.getenv("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")
|
| 13 |
+
|
| 14 |
+
# openai_api_key = os.getenv("OPENAI_API_KEY")
|
| 15 |
+
|
| 16 |
+
# if openai_api_key is None:
|
| 17 |
+
# raise ValueError("Kh贸a API OPENAI_API_KEY kh么ng t矛m th岷. Vui l貌ng ki峄僲 tra file .env.")
|
| 18 |
+
|
| 19 |
+
# img2text
|
| 20 |
+
def img2text(url):
|
| 21 |
+
image_to_text = pipeline("image-to-text", model = "Salesforce/blip-image-captioning-large")
|
| 22 |
+
|
| 23 |
+
text = image_to_text(url)[0]["generated_text"]
|
| 24 |
+
|
| 25 |
+
print(text)
|
| 26 |
+
return text
|
| 27 |
+
|
| 28 |
+
img2text("Blackpink.png")
|