eagle0504 commited on
Commit
996a2a0
Β·
verified Β·
1 Parent(s): e865b60

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +36 -7
  2. app.py +248 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,41 @@
1
  ---
2
- title: Card Generator
3
- emoji: πŸ“Š
4
- colorFrom: purple
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 6.0.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Holiday Card Generator
3
+ emoji: πŸŽ„
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: streamlit
7
+ sdk_version: 1.34.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
+ # Holiday Card Generator πŸŽ„
14
+
15
+ Create beautiful holiday-themed images for postcards and emails using AI! This app uses OpenAI's DALL-E 3 to generate custom holiday images based on your preferences.
16
+
17
+ ## Features
18
+
19
+ ✨ **9 Holiday Themes**: Christmas, New Year, Thanksgiving, Halloween, Easter, Valentine's Day, Fourth of July, Hanukkah, and Winter Holidays
20
+
21
+ 🎨 **Multiple Art Styles**: Realistic, Cartoon, Watercolor, Vintage Postcard, Modern Minimalist, and more
22
+
23
+ πŸ“± **Format Options**: Optimized for postcards, email headers, and social media posts
24
+
25
+ πŸ’Ύ **Easy Download**: One-click download of high-quality PNG images
26
+
27
+ ## How to Use
28
+
29
+ 1. Enter your OpenAI API key in the sidebar
30
+ 2. Select your favorite holiday theme
31
+ 3. Customize with additional details and art style
32
+ 4. Choose the image purpose (postcard, email, social media)
33
+ 5. Generate and download your beautiful holiday image!
34
+
35
+ ## Requirements
36
+
37
+ You'll need an OpenAI API key to use this app. Get yours at [OpenAI Platform](https://platform.openai.com/account/api-keys).
38
+
39
+ ---
40
+
41
+ Made with ❀️ using Streamlit and OpenAI DALL-E 3
app.py ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from PIL import Image
4
+ import io
5
+ import base64
6
+ from datetime import datetime
7
+ import time
8
+
9
+ # Configure page
10
+ st.set_page_config(
11
+ page_title="Holiday Image Creator",
12
+ page_icon="πŸŽ„",
13
+ layout="wide"
14
+ )
15
+
16
+ def generate_image_with_openai(prompt, api_key, size="1024x1024"):
17
+ """Generate image using OpenAI DALL-E API"""
18
+ try:
19
+ headers = {
20
+ "Authorization": f"Bearer {api_key}",
21
+ "Content-Type": "application/json"
22
+ }
23
+
24
+ data = {
25
+ "model": "dall-e-3",
26
+ "prompt": prompt,
27
+ "n": 1,
28
+ "size": size,
29
+ "quality": "standard"
30
+ }
31
+
32
+ response = requests.post(
33
+ "https://api.openai.com/v1/images/generations",
34
+ headers=headers,
35
+ json=data,
36
+ timeout=60
37
+ )
38
+
39
+ if response.status_code == 200:
40
+ result = response.json()
41
+ image_url = result['data'][0]['url']
42
+
43
+ # Download the image
44
+ img_response = requests.get(image_url, timeout=30)
45
+ if img_response.status_code == 200:
46
+ return Image.open(io.BytesIO(img_response.content))
47
+ else:
48
+ st.error("Failed to download generated image")
49
+ return None
50
+ else:
51
+ error_msg = response.json().get('error', {}).get('message', 'Unknown error')
52
+ st.error(f"API Error: {error_msg}")
53
+ return None
54
+
55
+ except requests.exceptions.Timeout:
56
+ st.error("Request timed out. Please try again.")
57
+ return None
58
+ except Exception as e:
59
+ st.error(f"Error generating image: {str(e)}")
60
+ return None
61
+
62
+ def create_download_link(image, filename):
63
+ """Create download link for image"""
64
+ buffered = io.BytesIO()
65
+ image.save(buffered, format="PNG")
66
+ img_str = base64.b64encode(buffered.getvalue()).decode()
67
+
68
+ href = f'<a href="data:image/png;base64,{img_str}" download="{filename}">Download Image</a>'
69
+ return href
70
+
71
+ def main():
72
+ # Sidebar for API configuration
73
+ st.sidebar.header("πŸ”‘ API Configuration")
74
+
75
+ api_key = st.sidebar.text_input(
76
+ "Enter your OpenAI API Key",
77
+ type="password",
78
+ help="Get your API key from https://platform.openai.com/account/api-keys"
79
+ )
80
+
81
+ st.sidebar.markdown("---")
82
+ st.sidebar.markdown("### πŸ“ Instructions")
83
+ st.sidebar.markdown("""
84
+ 1. Enter your OpenAI API key above
85
+ 2. Choose a holiday theme
86
+ 3. Customize your image details
87
+ 4. Generate and download your image
88
+ """)
89
+
90
+ st.sidebar.markdown("### 🎨 Image Formats")
91
+ image_size = st.sidebar.selectbox(
92
+ "Image Size",
93
+ ["1024x1024", "1792x1024", "1024x1792"],
94
+ help="Square, Landscape, or Portrait format"
95
+ )
96
+
97
+ # Main content
98
+ st.title("πŸŽ„ Holiday Image Creator")
99
+ st.markdown("Create beautiful holiday-themed images for postcards and emails!")
100
+
101
+ # Check if API key is provided
102
+ if not api_key:
103
+ st.warning("⚠️ Please enter your OpenAI API key in the sidebar to get started.")
104
+ st.info("You can get your API key from [OpenAI Platform](https://platform.openai.com/account/api-keys)")
105
+ return
106
+
107
+ # Holiday theme selection
108
+ col1, col2 = st.columns([2, 1])
109
+
110
+ with col1:
111
+ st.subheader("🎊 Choose Your Holiday Theme")
112
+
113
+ holiday_themes = {
114
+ "Christmas": "Christmas tree, Santa Claus, snow, presents, red and green colors",
115
+ "New Year": "Fireworks, champagne, countdown, golden colors, celebration",
116
+ "Thanksgiving": "Turkey, autumn leaves, pumpkins, warm colors, family gathering",
117
+ "Halloween": "Pumpkins, spooky decorations, orange and black colors, trick or treat",
118
+ "Easter": "Easter eggs, bunny, spring flowers, pastel colors, renewal",
119
+ "Valentine's Day": "Hearts, roses, pink and red colors, romantic theme",
120
+ "Fourth of July": "American flag, fireworks, red white and blue, patriotic",
121
+ "Hanukkah": "Menorah, dreidel, blue and white colors, Jewish celebration",
122
+ "Winter Holidays": "Snow, winter wonderland, cozy atmosphere, warm lights"
123
+ }
124
+
125
+ selected_theme = st.selectbox("Select Holiday Theme:", list(holiday_themes.keys()))
126
+
127
+ # Custom prompt input
128
+ st.subheader("✨ Customize Your Image")
129
+
130
+ custom_details = st.text_area(
131
+ "Additional Details (optional)",
132
+ placeholder="e.g., 'with a cute dog wearing a Santa hat', 'in watercolor style', 'vintage postcard design'",
133
+ help="Add specific elements, styles, or details to your image"
134
+ )
135
+
136
+ # Style options
137
+ style_options = [
138
+ "Realistic", "Cartoon/Illustrated", "Watercolor", "Vintage Postcard",
139
+ "Modern Minimalist", "Hand-drawn", "Digital Art", "Oil Painting"
140
+ ]
141
+
142
+ selected_style = st.selectbox("Art Style:", style_options)
143
+
144
+ with col2:
145
+ st.subheader("πŸ–ΌοΈ Preview Settings")
146
+
147
+ # Format selection
148
+ format_type = st.radio(
149
+ "Image Purpose:",
150
+ ["Postcard", "Email Header", "Social Media Post", "Custom"]
151
+ )
152
+
153
+ # Quality selection
154
+ if format_type == "Email Header":
155
+ recommended_size = "1792x1024"
156
+ elif format_type == "Social Media Post":
157
+ recommended_size = "1024x1024"
158
+ else:
159
+ recommended_size = image_size
160
+
161
+ st.info(f"πŸ’‘ Recommended size for {format_type}: {recommended_size}")
162
+
163
+ # Generate button
164
+ st.markdown("---")
165
+
166
+ if st.button("🎨 Generate Holiday Image", type="primary"):
167
+ if not api_key.strip():
168
+ st.error("Please enter your OpenAI API key first!")
169
+ return
170
+
171
+ # Construct the prompt
172
+ base_prompt = holiday_themes[selected_theme]
173
+
174
+ prompt = f"Create a beautiful {selected_theme} themed image with {base_prompt}"
175
+
176
+ if custom_details:
177
+ prompt += f", {custom_details}"
178
+
179
+ prompt += f", in {selected_style.lower()} style"
180
+
181
+ if format_type == "Postcard":
182
+ prompt += ", suitable for a holiday postcard"
183
+ elif format_type == "Email Header":
184
+ prompt += ", suitable for an email header banner"
185
+ elif format_type == "Social Media Post":
186
+ prompt += ", suitable for social media sharing"
187
+
188
+ prompt += ", high quality, festive and cheerful"
189
+
190
+ # Show the prompt being used
191
+ with st.expander("πŸ” View Generated Prompt"):
192
+ st.code(prompt)
193
+
194
+ # Generate image
195
+ with st.spinner("🎨 Creating your holiday image... This may take 10-30 seconds."):
196
+ try:
197
+ generated_image = generate_image_with_openai(prompt, api_key, image_size)
198
+
199
+ if generated_image:
200
+ st.success("βœ… Image generated successfully!")
201
+
202
+ # Display the image
203
+ st.subheader("πŸ–ΌοΈ Your Holiday Image")
204
+ st.image(generated_image, caption=f"{selected_theme} - {selected_style}", use_column_width=True)
205
+
206
+ # Download section
207
+ st.subheader("πŸ’Ύ Download Your Image")
208
+
209
+ # Generate filename
210
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
211
+ filename = f"holiday_{selected_theme.lower().replace(' ', '_')}_{timestamp}.png"
212
+
213
+ # Create download button
214
+ buffered = io.BytesIO()
215
+ generated_image.save(buffered, format="PNG")
216
+
217
+ st.download_button(
218
+ label="πŸ“₯ Download PNG Image",
219
+ data=buffered.getvalue(),
220
+ file_name=filename,
221
+ mime="image/png"
222
+ )
223
+
224
+ # Image info
225
+ st.info(f"πŸ“Š Image size: {generated_image.size[0]} x {generated_image.size[1]} pixels")
226
+
227
+ # Regenerate option
228
+ if st.button("πŸ”„ Generate Another Image"):
229
+ st.experimental_rerun()
230
+
231
+ except Exception as e:
232
+ st.error(f"❌ Error: {str(e)}")
233
+ st.error("Please check your API key and try again.")
234
+
235
+ # Footer
236
+ st.markdown("---")
237
+ st.markdown(
238
+ """
239
+ <div style='text-align: center; color: gray;'>
240
+ πŸŽ„ Happy Holidays! Create and share beautiful holiday images πŸŽ„<br>
241
+ Made with ❀️ using Streamlit and OpenAI DALL-E
242
+ </div>
243
+ """,
244
+ unsafe_allow_html=True
245
+ )
246
+
247
+ if __name__ == "__main__":
248
+ main()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit>=1.28.0
2
+ requests>=2.31.0
3
+ Pillow>=10.0.0