# import gradio as gr from dotenv import load_dotenv import gradio as gr # Load environment variables from the .env file de forma local load_dotenv() import base64 import requests with open("Iso_Logotipo_Ceibal.png", "rb") as image_file: encoded_image = base64.b64encode(image_file.read()).decode() import os from openai import OpenAI client=OpenAI(api_key=os.environ["OPENAI_API_KEY"]) api_key=os.environ["OPENAI_API_KEY"] def respond2(image,text): # with open('some_file.txt', 'w') as f: # f.write(processed_string) # Function to encode the image def encode_image(image_path): with open(image_path, "rb") as image_file: return base64.b64encode(image_file.read()).decode('utf-8') # Path to your image # Getting the base64 string base64_image = encode_image(image) headers = { "Content-Type": "application/json", "Authorization": f"Bearer {api_key}" } payload = { "model": "gpt-4-vision-preview", "messages": [ { "role": "user", "content": [ { "type": "text", "text": text }, { "type": "image_url", "image_url": { "url": f"data:image/jpeg;base64,{base64_image}", "detail": "low" } } ] } ], "max_tokens": 300 } response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload) print(response.json()) return response.json()['choices'][0]['message']['content'] with gr.Blocks() as demo: gr.Markdown( """