Commit
•
0aabc4c
1
Parent(s):
d869c4e
Update README.md
Browse files
README.md
CHANGED
@@ -14,6 +14,87 @@ tags:
|
|
14 |
library_name: transformers
|
15 |
---
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
<img src="molmo_logo.png" alt="Logo for the Molmo Project" style="width: auto; height: 50px;">
|
18 |
|
19 |
# Molmo 7B-D
|
|
|
14 |
library_name: transformers
|
15 |
---
|
16 |
|
17 |
+
# Molmo 7B-D Model Card with Endpoint Usage
|
18 |
+
|
19 |
+
This is a copy of the original [Molmo 7B-D model card](https://huggingface.co/allenai/Molmo-7B-D-0924) with additional information about using the model via Hugging Face Inference Endpoints.
|
20 |
+
|
21 |
+
## Using the Model via Inference Endpoints
|
22 |
+
|
23 |
+
**Note: The following implementation is a community-contributed endpoint handler and is not an official implementation. For the official model and its usage, please refer to the [official Molmo 7B-D model page](https://huggingface.co/allenai/Molmo-7B-D-0924).**
|
24 |
+
|
25 |
+
If you've deployed the model using Hugging Face's Inference Endpoints with a community-contributed handler, you can use it with the following code:
|
26 |
+
|
27 |
+
```python
|
28 |
+
import requests
|
29 |
+
import json
|
30 |
+
import base64
|
31 |
+
from IPython.display import Image, display
|
32 |
+
|
33 |
+
API_URL = YOUR_ENDPOINT_URL_HERE
|
34 |
+
headers = {
|
35 |
+
"Accept" : "application/json",
|
36 |
+
"Authorization": "Bearer hf_TOKEN_HERE",
|
37 |
+
"Content-Type": "application/json"
|
38 |
+
}
|
39 |
+
|
40 |
+
# Function to encode image to base64
|
41 |
+
def encode_image(image_path):
|
42 |
+
with open(image_path, "rb") as image_file:
|
43 |
+
return base64.b64encode(image_file.read()).decode('utf-8')
|
44 |
+
|
45 |
+
# Path to your local image file
|
46 |
+
image_path = "hf-logo-with-title.png"
|
47 |
+
|
48 |
+
# Display the image (if in a Jupyter notebook)
|
49 |
+
display(Image(filename=image_path))
|
50 |
+
|
51 |
+
# Encode the image
|
52 |
+
base64_image = encode_image(image_path)
|
53 |
+
|
54 |
+
# Prepare the payload
|
55 |
+
payload = {
|
56 |
+
"inputs": {
|
57 |
+
"image": base64_image,
|
58 |
+
"text_prompt": "Describe this image in detail."
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
# Make the POST request
|
63 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
64 |
+
|
65 |
+
# Check if the request was successful
|
66 |
+
if response.status_code == 200:
|
67 |
+
# Parse the JSON response
|
68 |
+
result = response.json()
|
69 |
+
print(result)
|
70 |
+
else:
|
71 |
+
print("Error:", response.status_code)
|
72 |
+
print("Response:", response.text)
|
73 |
+
|
74 |
+
# Print some debug information
|
75 |
+
print("\nDebug Information:")
|
76 |
+
print(f"API URL: {API_URL}")
|
77 |
+
print(f"Image Path: {image_path}")
|
78 |
+
print(f"Payload size: {len(json.dumps(payload))} bytes")
|
79 |
+
print(f"Response status code: {response.status_code}")
|
80 |
+
```
|
81 |
+
|
82 |
+
Example output:
|
83 |
+
|
84 |
+
```
|
85 |
+
[{'generated_text': ' The image features a simple, cartoon-style emoji on the left side, set against a white background. The emoji is a yellow circle with a white outline, depicting a smiling face with black eyes and a red tongue sticking out. The face has two small yellow dots on its cheeks, giving it a cheerful expression. The emoji\'s hands are positioned in front of its chest, as if it is hugging itself. To the right of the emoji, in large, dark blue text, the words "Hugging Face" are displayed. The overall design is minimalistic, with the emoji and text being the only elements in the image.'}]
|
86 |
+
```
|
87 |
+
|
88 |
+
This code snippet demonstrates how to use the model with an image file, encode it to base64, and send it to the inference endpoint for processing. Make sure to replace `"hf_TOKEN_HERE"` with your actual Hugging Face API token.
|
89 |
+
|
90 |
+
Remember that this is a community implementation and may not reflect the most up-to-date or official way to use the model. For the latest official information and usage instructions, always refer to the [official Molmo 7B-D model page](https://huggingface.co/allenai/Molmo-7B-D-0924).
|
91 |
+
|
92 |
+
---
|
93 |
+
|
94 |
+
# Original Molmo 7B-D Model Card
|
95 |
+
|
96 |
+
The content below is a copy of the original model card. For the most up-to-date information, please refer to the [official Molmo 7B-D model page](https://huggingface.co/allenai/Molmo-7B-D-0924).
|
97 |
+
|
98 |
<img src="molmo_logo.png" alt="Logo for the Molmo Project" style="width: auto; height: 50px;">
|
99 |
|
100 |
# Molmo 7B-D
|