Update README.md
Browse files
README.md
CHANGED
|
@@ -13,3 +13,115 @@ tags:
|
|
| 13 |
- flux
|
| 14 |
---
|
| 15 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
- flux
|
| 14 |
---
|
| 15 |

|
| 16 |
+
|
| 17 |
+
# **JSONify-Flux: A Vision-Language Model for Image Captioning & OCR**
|
| 18 |
+
|
| 19 |
+
The **JSONify-Flux** model is a fine-tuned version of Qwen2-VL, specifically tailored for **Flux-generated image analysis**, **caption extraction**, and **structured JSON formatting**. This model is optimized for tasks involving **image-to-text conversion**, **Optical Character Recognition (OCR)**, and **context-aware structured data extraction**.
|
| 20 |
+
|
| 21 |
+
#### Key Enhancements:
|
| 22 |
+
|
| 23 |
+
* **Advanced Image Understanding**: JSONify-Flux has been trained using **30 million trainable parameters** on **Flux-generated images and their captions**, ensuring precise image comprehension.
|
| 24 |
+
|
| 25 |
+
* **Optimized for JSON Output**: The model is designed to output structured JSON data, making it suitable for integration with databases, APIs, and automation pipelines.
|
| 26 |
+
|
| 27 |
+
* **Enhanced OCR Capabilities**: JSONify-Flux excels in recognizing and extracting text from images with a high degree of accuracy.
|
| 28 |
+
|
| 29 |
+
* **Multimodal Processing**: Supports both image and text inputs while generating structured JSON-formatted outputs.
|
| 30 |
+
|
| 31 |
+
* **Multilingual Support**: Trained to recognize text inside images in multiple languages, including English, Chinese, European languages, Japanese, Korean, Arabic, and more.
|
| 32 |
+
|
| 33 |
+
### How to Use
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
|
| 37 |
+
from qwen_vl_utils import process_vision_info
|
| 38 |
+
|
| 39 |
+
# Load the model with optimized parameters
|
| 40 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 41 |
+
"prithivMLmods/JSONify-Flux", torch_dtype="auto", device_map="auto"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Recommended acceleration for performance optimization
|
| 45 |
+
# model = Qwen2VLForConditionalGeneration.from_pretrained(
|
| 46 |
+
# "prithivMLmods/JSONify-Flux",
|
| 47 |
+
# torch_dtype=torch.bfloat16,
|
| 48 |
+
# attn_implementation="flash_attention_2",
|
| 49 |
+
# device_map="auto",
|
| 50 |
+
# )
|
| 51 |
+
|
| 52 |
+
# Default processor
|
| 53 |
+
processor = AutoProcessor.from_pretrained("prithivMLmods/JSONify-Flux")
|
| 54 |
+
|
| 55 |
+
messages = [
|
| 56 |
+
{
|
| 57 |
+
"role": "user",
|
| 58 |
+
"content": [
|
| 59 |
+
{
|
| 60 |
+
"type": "image",
|
| 61 |
+
"image": "https://flux-generated.com/sample_image.jpeg",
|
| 62 |
+
},
|
| 63 |
+
{"type": "text", "text": "Extract structured information from this image in JSON format."},
|
| 64 |
+
],
|
| 65 |
+
}
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
# Prepare for inference
|
| 69 |
+
text = processor.apply_chat_template(
|
| 70 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 71 |
+
)
|
| 72 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 73 |
+
inputs = processor(
|
| 74 |
+
text=[text],
|
| 75 |
+
images=image_inputs,
|
| 76 |
+
videos=video_inputs,
|
| 77 |
+
padding=True,
|
| 78 |
+
return_tensors="pt",
|
| 79 |
+
)
|
| 80 |
+
inputs = inputs.to("cuda")
|
| 81 |
+
|
| 82 |
+
# Generate output
|
| 83 |
+
generated_ids = model.generate(**inputs, max_new_tokens=256)
|
| 84 |
+
generated_ids_trimmed = [
|
| 85 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 86 |
+
]
|
| 87 |
+
output_text = processor.batch_decode(
|
| 88 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 89 |
+
)
|
| 90 |
+
print(output_text)
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
### JSON Output Example:
|
| 94 |
+
```json
|
| 95 |
+
{
|
| 96 |
+
"image_id": "sample_image.jpeg",
|
| 97 |
+
"captions": [
|
| 98 |
+
"A futuristic cityscape with neon lights.",
|
| 99 |
+
"A digital artwork featuring an abstract environment."
|
| 100 |
+
],
|
| 101 |
+
"recognized_text": "Welcome to Flux City!",
|
| 102 |
+
"metadata": {
|
| 103 |
+
"color_palette": ["#FF5733", "#33FF57", "#3357FF"],
|
| 104 |
+
"detected_objects": ["building", "sign", "street light"]
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### **Key Features**
|
| 110 |
+
|
| 111 |
+
1. **Flux-Based Training Data**
|
| 112 |
+
- Trained using **Flux-generated images** and captions to ensure high-quality structured output.
|
| 113 |
+
|
| 114 |
+
2. **Optical Character Recognition (OCR)**
|
| 115 |
+
- Extracts and processes textual content within images.
|
| 116 |
+
|
| 117 |
+
3. **Structured JSON Output**
|
| 118 |
+
- Outputs information in **JSON format** for easy integration with various applications.
|
| 119 |
+
|
| 120 |
+
4. **Conversational Capabilities**
|
| 121 |
+
- Handles **multi-turn interactions** with structured responses.
|
| 122 |
+
|
| 123 |
+
5. **Image & Text Processing**
|
| 124 |
+
- Inputs can include **images, text, or both**, with JSON-formatted results.
|
| 125 |
+
|
| 126 |
+
6. **Secure and Optimized Model Weights**
|
| 127 |
+
- Uses **Safetensors** for enhanced security and efficient model loading.
|