Overview
- Introduction
- Setup/Install
- Quickstart
Concepts
- DataSources
- JOBS & Automation
- AI-Tables
Use Cases
- Fine-Tuning
- Chatbots with Agents
- Chatbots with Jobs
- Content Generation
- Semantic Search
- Recommenders
- Question Answering
- Sentiment Analysis
- Text Summarization
- Forecasting
- Classification
- Regression
- Natural Language Processing
- Community Tutorials List
Generating Images with OpenAI
In this tutorial, we’ll generate images with the help of AI.
You can build a Twitter chatbot that converts text prompts into images. Follow this blog post to see the total workflow.
Creating a Model
Let’s create an OpenAI model. Follow this instruction to set up the OpenAI integration in MindsDB.
Before creating an OpenAI model, please create an engine, providing your OpenAI API key:
CREATE ML_ENGINE openai_engine
FROM openai
USING
api_key = 'your-openai-api-key';
CREATE MODEL mindsdb.dalle
PREDICT img_url
USING
engine = 'openai_engine',
mode = 'image',
prompt_template = '{{text}}, 8K | highly detailed realistic 3d oil painting style cyberpunk by MAD DOG JONES combined with Van Gogh | cinematic lighting | happy colors';
This model connects to the OpenAI’s DALL-E engine for generating images. The {{text}}
variable present in the prompt_template
parameter is replaced with the user’s input.
Generating Images
Now that the model is ready, we can generate some images.
SELECT text, img_url
FROM mindsdb.dalle
WHERE text = 'a cute robot helping a little kid build a better world';
On execution, we get:
+--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| text | img_url |
+--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| a cute robot helping a little kid build a better world | https://oaidalleapiprodscus.blob.core.windows.net/private/org-1QXk2w4H0OhDrF2Hd4QV5K2c/user-piMc91jPmVdhttPLHl2y50E7/img-p5NROyoV5ysWWUY91xhQUZdg.png?st=2023-05-29T16%3A45%3A02Z&se=2023-05-29T18%3A45%3A02Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-05-29T10%3A29%3A15Z&ske=2023-05-30T10%3A29%3A15Z&sks=b&skv=2021-08-06&sig=vUI9vedjWtA7L0J3V0/4c05Wzh1Kf2/zyl%2BN1yfK6rU%3D |
+--------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
The model provides a link to the generated image.
Let’s try another prompt.
SELECT text, img_url
FROM mindsdb.dalle
WHERE text = 'design of a happy tree house';
On execution, we get:
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| text | img_url |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| design of a happy tree house | https://oaidalleapiprodscus.blob.core.windows.net/private/org-1QXk2w4H0OhDrF2Hd4QV5K2c/user-piMc91jPmVdhttPLHl2y50E7/img-O1GPmdmuoRXFTGdUjahOf1Ws.png?st=2023-05-29T16%3A50%3A34Z&se=2023-05-29T18%3A50%3A34Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-05-29T17%3A03%3A23Z&ske=2023-05-30T17%3A03%3A23Z&sks=b&skv=2021-08-06&sig=9vY%2Bqr/0CrzqqdM4uYEa/XwYXMBn67RBodhzsg%2Bs9ag%3D |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Here is the generated image:
Check out how to implement a Twitter chatbot that answers by generating images. Follow this link to learn more.