File size: 2,054 Bytes
5934eb7
f077aa0
783695c
f077aa0
2466fdb
5dc0d7d
f077aa0
 
5934eb7
f077aa0
2fe9ea1
 
f077aa0
 
 
 
 
 
 
 
2fe9ea1
 
 
f077aa0
783695c
5934eb7
f077aa0
 
5934eb7
f077aa0
783695c
f077aa0
5934eb7
783695c
62a8ecb
783695c
f077aa0
783695c
 
2466fdb
783695c
 
 
f077aa0
783695c
f077aa0
 
783695c
f077aa0
 
783695c
f077aa0
 
783695c
 
5934eb7
f077aa0
 
783695c
5934eb7
f077aa0
 
b9b2ec9
62a8ecb
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
60
61
62
63
64
65
import streamlit as st
from PIL import Image
import requests
import io
import base64

# Set page config
st.set_page_config(page_title="AI Image Generator", page_icon="🎨", layout="wide")

# Custom CSS
st.markdown("""
<style>
.stApp {
    background-color: #f0f0f5;
}
.stButton>button {
    background-color: #4CAF50;
    color: white;
    font-weight: bold;
}
</style>
""", unsafe_allow_html=True)

# Title
st.title("🎨 AI Image Generator (Dalle-mini)")

# Input area
prompt = st.text_area("Enter your image description:", height=100)

# Generate button
if st.button("Generate Image"):
    if prompt:
        try:
            with st.spinner("Generating your masterpiece..."):
                # Make a request to the Dalle-mini API (Craiyon)
                response = requests.post("https://backend.craiyon.com/generate", json={"prompt": prompt})
                
                if response.status_code == 200:
                    image_data = response.json()['images'][0]
                    image = Image.open(io.BytesIO(base64.b64decode(image_data)))
                    
                    # Display the image
                    st.image(image, caption="Generated Image", use_column_width=True)
                    
                    # Add download button
                    buf = io.BytesIO()
                    image.save(buf, format="PNG")
                    st.download_button(
                        label="Download Image",
                        data=buf.getvalue(),
                        file_name="generated_image.png",
                        mime="image/png"
                    )
                else:
                    st.error("Failed to generate image. Please try again.")
        except Exception as e:
            st.error(f"An error occurred: {str(e)}")
    else:
        st.warning("Please enter a prompt to generate an image.")

# Footer
st.markdown("---")
st.markdown("Created with ❤️ for 3EyeDimensions AI Engineer Internship")
st.markdown("Note: This app uses the Dalle-mini model for image generation.")