generated from streamlit/streamlit-hello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHello.py
59 lines (50 loc) · 2.3 KB
/
Hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import streamlit as st
import openai
def openai_image(prompt):
client = openai.OpenAI(api_key=st.secrets["OPENAI_KEY"])
response = client.images.generate(
prompt=prompt,
n=1,
size="256x256"
)
image_url = response.data[0].url
return image_url
def run():
st.set_page_config(
page_title="OpenAI",
page_icon="✨",
)
st.title("Generate your own image!")
col1,col2 = st.columns([3,5])
#Choices
image_style = col2.selectbox('Choose your painting style',["A photo of ", "An oil painting of ","A manga drawing of "])
number = col2.text_input("Number of animals")
animal = col2.selectbox('Choose your animal',[" fuzzy pandas "," british shorthair cats "," Persian Cats "," Shiba Inu Dogs "," racoons "])
hat = col2.selectbox("Choose your hat",["wearing a fedora and ","wearing a cowboy hat and ","wearing a motorcycle helmet and "])
outfit = col2.selectbox("Choose your outfit",["red shirt ","black leather jacket "])
activity = col2.selectbox("Choose an activity",["playing a guitar ","skateboarding ","riding a bike "])
location = col2.selectbox("Choose a location",["on a beach ","in a garden ","on top of a mountain "])
additional_details = col2.text_area("Any additional details for prompt engineering")
prompt = image_style + number + animal + hat + outfit + activity + location + additional_details
st.write("Your choice is: " + prompt)
image_button = st.button("Generate image!")
if image_button:
with col1:
with st.spinner("Loading..."):
image_url = openai_image(prompt)
st.image(image_url,caption="Generated by OpenAI")
if __name__ == "__main__":
run()