pratikshahp commited on
Commit
8b98084
verified
1 Parent(s): 27e08b6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ from PIL import Image
4
+ import openai
5
+
6
+ # Set your OpenAI API key
7
+ openai.api_key = 'your-openai-api-key'
8
+
9
+ def generate_image(input_text):
10
+ # Call OpenAI's DALL路E model for image generation
11
+ response = openai.Image.create(
12
+ prompt=input_text,
13
+ n=1,
14
+ size="1024x1024"
15
+ )
16
+ # Extract the image URL from the response
17
+ image_url = response['data'][0]['url']
18
+ return image_url
19
+
20
+ st.title("Text to Image Generation App with OpenAI") # Set Streamlit app title
21
+ input_text = st.text_input("Enter your image description:", "") # Text input for prompt
22
+
23
+ if st.button("Generate Image"): # Button to generate image
24
+ if input_text.strip() != "": # Ensure the input is not empty
25
+ # Generate image based on the prompt
26
+ img_url = generate_image(input_text)
27
+ # Display the generated image
28
+ st.image(img_url, caption="Generated Image")
29
+ else:
30
+ st.warning("Please enter a description for the image.")