ZaryabKhan14 commited on
Commit
a6a2fb2
1 Parent(s): 6591c5d

Upload 2 files

Browse files
Files changed (2) hide show
  1. main.py +38 -0
  2. requirements.txt +0 -0
main.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import streamlit as st
4
+ from openai import OpenAI
5
+ from dotenv import load_dotenv
6
+
7
+ load_dotenv()
8
+ api_key = os.getenv("api_key")
9
+ # Set your OpenAI API key
10
+ client = OpenAI(api_key=api_key)
11
+
12
+ # Streamlit app title and description
13
+ st.title("Text To Image Generator")
14
+ st.write("Enter a prompt to generate an image!")
15
+
16
+ # User input for the prompt
17
+ user_input = st.text_input("Enter a prompt:")
18
+
19
+ # Function to generate and display the image
20
+ def generate_and_display_image(text, model="dall-e-3", size="1024x1024", quality="standard"):
21
+ try:
22
+ response = client.images.generate(
23
+ model=model,
24
+ prompt=text,
25
+ size=size,
26
+ quality=quality,
27
+ n=1
28
+ )
29
+ image_url = response.data[0].url
30
+ st.image(image_url,width=800) # Display the image in the Streamlit app
31
+ except Exception as e:
32
+ st.error(f"An error occurred: {e}")
33
+
34
+ # Generate and display the image when the user clicks a button
35
+ if st.button("Generate Image"):
36
+ generate_and_display_image(user_input)
37
+
38
+ # Optionally, you can add more Streamlit components for further customization.
requirements.txt ADDED
Binary file (2.1 kB). View file