I have written the code as the per the instructions provided but I am not able to get the desired output. Below is the screenshot
My code:
import openai
from flask import Flask,render_template_string, request
openai.api_key=“OPENAI_API_KEY”
def generate_tutorial(components):
response = openai.Image.create(
prompt=components,
model=“image-alpha-001”,
size=“1024x1024”,
response_format=“url”
)
image_url = response[“data”][0][“url”]
return image_url
app= Flask(name)
@app.route(‘/’,methods=[‘GET’,‘POST’])
def hello():
output = “”
if request.method== ‘POST’:
components= request.form[‘components’]
output= generate_tutorial(components)
return render_template_string(‘’’
Custom Image Generator
<label for="components" class="form-label">Textual Description of the Image:</label>
<input type="text" class="form-control" id="components" name="components" placeholder="Enter the Description (Ex: A Lion in a Cage)" required>
Share with the Image
Output:
<button class="btn btn-secondary btn-sm" onclick="copyToClipboard()">Copy</button>
<p id="output" style="white-space: pre-wrap;">Generating an image for you...</p>
<img id="myImage" src="">
‘’',
output=output)
@app.route(‘/generate’,methods=[“POST”])
def generate():
components=request.form[‘components’]
return generate_tutorial(components)
if name == ‘main’:
app.run(host=‘0.0.0.0’, port=8080)