-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
20 lines (18 loc) · 886 Bytes
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Import necessary libraries and modules
import openai
from diffusers import StableDiffusionPipeline
import torch
# Function to generate AI-based images using OpenAI DALL-E
def generate_images_using_openai(text):
# Create an image using OpenAI's DALL-E model
response = openai.Image.create(prompt=text, n=1, size="512x512")
image_url = response['data'][0]['url']
return image_url
# Function to generate AI-based images using Huggingface Diffusers
def generate_images_using_huggingface_diffusers(text):
# Load the StableDiffusionPipeline from Huggingface
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe = pipe.to("cuda") # Transfer the model to GPU if available
prompt = text
image = pipe(prompt).images[0] # Generate the image using the prompt
return image