mirror of
https://github.com/ollama/ollama-python.git
synced 2026-09-16 07:39:54 +00:00
Add image generation support (#616)
This commit is contained in:
@@ -78,6 +78,12 @@ Configuration to use with an MCP client:
|
||||
- [multimodal-chat.py](multimodal-chat.py)
|
||||
- [multimodal-generate.py](multimodal-generate.py)
|
||||
|
||||
### Image Generation (Experimental) - Generate images with a model
|
||||
|
||||
> **Note:** Image generation is experimental and currently only available on macOS.
|
||||
|
||||
- [generate-image.py](generate-image.py)
|
||||
|
||||
### Structured Outputs - Generate structured outputs with a model
|
||||
|
||||
- [structured-outputs.py](structured-outputs.py)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Image generation is experimental and currently only available on macOS
|
||||
|
||||
import base64
|
||||
|
||||
from ollama import generate
|
||||
|
||||
prompt = 'a sunset over mountains'
|
||||
print(f'Prompt: {prompt}')
|
||||
|
||||
for response in generate(model='x/z-image-turbo', prompt=prompt, stream=True):
|
||||
if response.image:
|
||||
# Final response contains the image
|
||||
with open('output.png', 'wb') as f:
|
||||
f.write(base64.b64decode(response.image))
|
||||
print('\nImage saved to output.png')
|
||||
elif response.total:
|
||||
# Progress update
|
||||
print(f'Progress: {response.completed or 0}/{response.total}', end='\r')
|
||||
Reference in New Issue
Block a user