Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from haystack.components.generators import HuggingFaceTGIGenerator
|
|
| 5 |
from haystack.components.builders.prompt_builder import PromptBuilder
|
| 6 |
from haystack import Pipeline
|
| 7 |
from haystack.utils import Secret
|
|
|
|
| 8 |
from image_captioner import ImageCaptioner
|
| 9 |
|
| 10 |
description = """
|
|
@@ -15,7 +16,9 @@ description = """
|
|
| 15 |
* Choose your model
|
| 16 |
* ✨ Captionate! ✨
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
Built by [Bilge Yucel](https://twitter.com/bilgeycl) using [Haystack 2.0](https://github.com/deepset-ai/haystack) 💙
|
| 21 |
"""
|
|
@@ -32,7 +35,7 @@ hf_api_key = os.environ["HF_API_KEY"]
|
|
| 32 |
|
| 33 |
def generate_caption(image_file_path, model_name):
|
| 34 |
image_to_text = ImageCaptioner(
|
| 35 |
-
model_name="
|
| 36 |
)
|
| 37 |
prompt_builder = PromptBuilder(template=prompt_template)
|
| 38 |
generator = HuggingFaceTGIGenerator(model=model_name, token=Secret.from_token(hf_api_key), generation_kwargs={"max_new_tokens":50})
|
|
|
|
| 5 |
from haystack.components.builders.prompt_builder import PromptBuilder
|
| 6 |
from haystack import Pipeline
|
| 7 |
from haystack.utils import Secret
|
| 8 |
+
|
| 9 |
from image_captioner import ImageCaptioner
|
| 10 |
|
| 11 |
description = """
|
|
|
|
| 16 |
* Choose your model
|
| 17 |
* ✨ Captionate! ✨
|
| 18 |
|
| 19 |
+
It uses [Salesforce/blip-image-captioning-base](https://huggingface.co/Salesforce/blip-image-captioning-base) model for image2task caption generation task.
|
| 20 |
+
|
| 21 |
+
For Instagrammable captions, `mistralai/Mistral-7B-Instruct-v0.2` performs best, but try different models to see how they react to the same prompt.
|
| 22 |
|
| 23 |
Built by [Bilge Yucel](https://twitter.com/bilgeycl) using [Haystack 2.0](https://github.com/deepset-ai/haystack) 💙
|
| 24 |
"""
|
|
|
|
| 35 |
|
| 36 |
def generate_caption(image_file_path, model_name):
|
| 37 |
image_to_text = ImageCaptioner(
|
| 38 |
+
model_name="Salesforce/blip-image-captioning-base",
|
| 39 |
)
|
| 40 |
prompt_builder = PromptBuilder(template=prompt_template)
|
| 41 |
generator = HuggingFaceTGIGenerator(model=model_name, token=Secret.from_token(hf_api_key), generation_kwargs={"max_new_tokens":50})
|