Closed
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
APIRemovedInV1
openai.lib._old_api.APIRemovedInV1:
You tried to access openai.Image, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python for the API.
You can run openai migrate
to automatically upgrade your codebase to use the 1.0.0 interface.
Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28
A detailed migration guide is available here: #742
To Reproduce
a
Code snippets
from flask import Flask, render_template, request, jsonify, send_file
import openai
import requests
from PIL import Image
from io import BytesIO
openai migrate
# Initialize Flask app
app = Flask(__name__)
# Set your OpenAI API key
openai.api_key = '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'
# Define a route for the home page
@app.route('/')
def home():
return render_template('login.html')
# Define a route to handle image generation
@app.route('/generate', methods=['POST'])
def generate_image():
# Get the text prompt from the form submission
text = request.form['text_prompt']
# Call the OpenAI API to generate the image
response = openai.Image.create(prompt=text, n=1, size="256x256")
# Get the URL of the generated image
image_url = response['data'][0]['url']
# Fetch the image using the URL
image_response = requests.get(image_url)
# Convert the image response to a PIL Image
image = Image.open(BytesIO(image_response.content))
# Save the image to a buffer
buf = BytesIO()
image.save(buf, format='PNG')
buf.seek(0)
# Send the image as a response
return send_file(buf, mimetype='image/png')
# Run the Flask app
if __name__ == '__main__':
app.run(debug=True)
OS
windows 11
Python version
python.11.8
Library version
openai1.10.0