import gradio as gr from groq import Groq import base64 client = Groq(api_key = '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') def encode_image(image_path) : with open(image_path , 'rb') as image_file : return base64.b64encode(image_file.read()).decode('utf-8') def analyze_image(image_path , prompt) : base64_image = encode_image(image_path) chat_completion = client.chat.completions.create( messages = [ { 'role': 'user' , 'content' : [ { 'type' : 'text' , 'text' : prompt } , { 'type' : 'image_url' , 'image_url' : {'url' : f'data:image/jpeg;base64,{base64_image}'} } ] } ] , model = 'llama-3.2-90b-vision-preview' ) return chat_completion.choices[0].message.content demo = gr.Interface( fn=analyze_image, inputs=[ gr.Image(type = 'filepath') , gr.Textbox(label = 'Prompt' , placeholder = 'Describe the Image' ) ], outputs = 'text' ) demo.launch()