├── Llama4ScoutImages.gif ├── README.md └── Terminal_Llama4_API.py /Llama4ScoutImages.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fabiomatricardi/Llama4Scout-MM-API/main/Llama4ScoutImages.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Llama4Scout-MM-API 2 | Terminal Chat with image/text to Llama 4 Scout on openrouter 3 | 4 | 5 | 6 | ### Get a free API key 7 | Register to [openrouter](https://openrouter.ai/) and create a free API key 8 | 9 | ### Clone the repo 10 | ``` 11 | git clone https://github.com/fabiomatricardi/Llama4Scout-MM-API.git 12 | cd Llama4Scout-MM-API 13 | ``` 14 | 15 | ## Install dependencies 16 | ``` 17 | pip install openai rich easygui pillow --upgrade 18 | ``` 19 | 20 | ### Run the python app 21 | ``` 22 | python Terminal_Llama4_API.py 23 | ``` 24 | 25 | 26 | -------------------------------------------------------------------------------- /Terminal_Llama4_API.py: -------------------------------------------------------------------------------- 1 | import base64 2 | from openai import OpenAI 3 | from easygui import fileopenbox 4 | from PIL import Image 5 | import io 6 | from datetime import datetime 7 | from rich.prompt import Prompt # https://rich.readthedocs.io/en/latest/ 8 | 9 | #Ask for your openrouter API key 10 | APIKey = Prompt.ask("Enter your Openrouter API key: ", password=True) 11 | 12 | # Function to encode the image 13 | def encode_image(image_path): 14 | with open(image_path, "rb") as image_file: 15 | return base64.b64encode(image_file.read()).decode("utf-8") 16 | 17 | # Path to your image 18 | print('Pick one image from your local PC...') 19 | image_path = fileopenbox(msg='Pick your image', default='*.jpg') 20 | #Display the image side by side in oS window 21 | selectedImage = Image.open(image_path) 22 | print('Opening the image in your Operating System...') 23 | selectedImage.show('Your uploaded Image') 24 | 25 | print('Encoding the image...') 26 | # Getting the Base64 string 27 | base64_image = encode_image(image_path) 28 | 29 | print('Connecting to Openrouter Llama4 Scout...') 30 | client = OpenAI( 31 | base_url="https://openrouter.ai/api/v1", 32 | api_key=APIKey, 33 | ) 34 | start = datetime.now() 35 | print('Reply:') 36 | stream = client.chat.completions.create( 37 | extra_headers={}, 38 | extra_body={}, 39 | model="meta-llama/llama-4-scout:free", 40 | messages=[ 41 | { 42 | "role": "user", 43 | "content": [ 44 | { 45 | "type": "text", 46 | "text": "What is in this image?" 47 | }, 48 | { 49 | "type": "image_url", 50 | "image_url": { 51 | "url": f"data:image/jpeg;base64,{base64_image}", 52 | } 53 | } 54 | ] 55 | } 56 | ], 57 | max_tokens=1024, 58 | stream=True, 59 | temperature=0.4) 60 | # Print the straming from the API call 61 | for chunk in stream: 62 | print(chunk.choices[0].delta.content, end='',flush=True) 63 | end = datetime.now() - start 64 | print('\n---\n') 65 | print(f'Completed in {end.total_seconds():.1f} seconds') --------------------------------------------------------------------------------