Skip to content

Commit

Permalink
adding gpt4o-mini and testing dalle for slidev images
Browse files Browse the repository at this point in the history
  • Loading branch information
JAlcocerT committed Jul 22, 2024
1 parent 6fb78c1 commit 86e76b5
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Streamlit_Pages/Streamlit_OpenAI.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def page_three():

model_choice = st.selectbox(
'Choose the model:',
['gpt-3.5-turbo', 'gpt-4-turbo-preview', 'gpt-4o'],
['gpt-3.5-turbo', 'gpt-4-turbo-preview', 'gpt-4o', 'gpt-4o-mini'],
index=0
)

Expand Down
27 changes: 27 additions & 0 deletions Z_Tests/Pict_for_SliDev-DaLLe/DaLLe2SliDev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import openai #0.28.1
import requests
import os

# Set your OpenAI API key here
openai.api_key = 'sk-proj-...'

# Define the prompt for the image generation
#prompt = "A futuristic cityscape with flying cars and neon lights"
prompt = "A calm city with parks. Realistic look."

# Generate the image
response = openai.Image.create(
prompt=prompt,
n=1, # Number of images to generate
size="1024x1024", # Size of the image
)

# Get the URL of the generated image
image_url = response['data'][0]['url']

# Download the image
image_data = requests.get(image_url).content
with open('generated_image.png', 'wb') as handler:
handler.write(image_data)

print("Image generated and saved as 'generated_image.png'")
63 changes: 63 additions & 0 deletions Z_Tests/Pict_for_SliDev-DaLLe/Dalle3SliDev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import openai
import requests
import os
import toml
from dotenv import load_dotenv

# Function to load the API key
def load_openai_api_key():
# First, check if the API key is provided as an environment variable
api_key = os.getenv('OPENAI_API_KEY')
if api_key:
return api_key

# If not found, try to load it from the .env file
load_dotenv()
api_key = os.getenv('OPENAI_API_KEY')
if api_key:
return api_key

# If still not found, try to load it from the .toml file
try:
config = toml.load('../../.streamlit/secrets.toml')
api_key = config['OPENAI_API_KEY'] #config['openai']['api_key']
return api_key
except FileNotFoundError:
print("Error: secrets.toml file not found.")
except KeyError:
print("Error: API key not found in secrets.toml.")

# If the API key is still not found, raise an error
raise ValueError("OpenAI API key is not set. Please set it as an environment variable, in the .env file, or in the .toml file.")


# Set your OpenAI API key here
#openai.api_key = 'sk-proj-'
# config = toml.load('../../.streamlit/secrets.toml')
# #config['openai']['api_key']

# # Create an OpenAI client
# #client = openai.OpenAI()
client = openai.OpenAI(api_key=load_openai_api_key())

# Define the prompt for the image generation
prompt = "A futuristic cityscape with flying cars and neon lights"

# Generate the image using a specific model #https://platform.openai.com/docs/guides/images/generations
response = client.images.generate(
model="dall-e-3", # Specify the model here
prompt=prompt,
size="1024x1024", # Size of the image
quality="standard", # Quality of the image
n=1 # Number of images to generate
)

# Get the URL of the generated image
image_url = response.data[0].url

# Download and save the image
image_data = requests.get(image_url).content
with open('generated_image22.png', 'wb') as handler:
handler.write(image_data)

print("Image generated and saved as 'generated_image22.png'")
24 changes: 24 additions & 0 deletions Z_Tests/Pict_for_SliDev-DaLLe/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* https://platform.openai.com/docs/guides/images/usage?context=python

```sh
export OPENAI_API_KEY=your-api-key-here
set OPENAI_API_KEY="your-api-key-here"
```

* Get it from the server with:

```sh
sftp [email protected]
get /home/serveruser/dalle/generated_image22.png C:\Users\desktopuser\Desktop\Streamlit-MultiChat\Z_Tests\generated_image.png
```

* Or with:

```sh
python3 -m http.server 8000

Invoke-WebRequest -Uri http://192.168.3.200:8000/generated_image22.png -OutFile C:\Users\Jesus_Alcocer\Desktop\Streamlit-MultiChat\Z_Tests\generated_image22.png


curl http://192.168.3.200:8000/generated_image22.png --output C:\Users\Jesus_Alcocer\Desktop\Streamlit-MultiChat\Z_Tests\generated_image.png
```

0 comments on commit 86e76b5

Please sign in to comment.