-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage_gen.py
More file actions
24 lines (20 loc) · 789 Bytes
/
image_gen.py
File metadata and controls
24 lines (20 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import streamlit as st
import openai
import requests
def generate_image(prompt):
response = openai.Image.create(
prompt=prompt,
n=1,
size="512x512"
)
image_url = response['data'][0]['url']
return image_url
def image_gen_interface():
st.title("Image generation interface ")
image_input_form = st.form(key='image_input_form')
image_input = image_input_form.text_input(label='Enter the prompt for image generation:')
image_input_submit = image_input_form.form_submit_button(label='Submit')
if image_input_submit:
image_url = generate_image(image_input)
st.download_button(label="Download image", data=requests.get(image_url).content, file_name="output_image.png", mime="image/png")
st.image(image_url)