Spaces:
Sleeping
Sleeping
Create test_openai.py
Browse files- test_openai.py +20 -0
test_openai.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
|
3 |
+
# Set your OpenAI API key
|
4 |
+
openai.api_key = "YOUR_OPENAI_API_KEY" # Replace with your OpenAI API key
|
5 |
+
|
6 |
+
# Define a quote
|
7 |
+
random_text = "The only way to do great work is to love what you do."
|
8 |
+
|
9 |
+
# Call OpenAI's DALL路E model to generate an image from the quote
|
10 |
+
response = openai.Image.create(
|
11 |
+
prompt=random_text, # Use the random quote as the prompt
|
12 |
+
n=1, # Generate 1 image
|
13 |
+
size="1024x1024" # Image size
|
14 |
+
)
|
15 |
+
|
16 |
+
# Extract the image URL from the response
|
17 |
+
image_url = response['data'][0]['url']
|
18 |
+
|
19 |
+
# Print the image URL
|
20 |
+
print(f"Image URL: {image_url}")
|