Spaces:
Build error
Build error
updated
Browse files2 unmodified lines345678910111213141516171819202122232425262728292 unmodified linesimport iofrom utils import query_hf_api# Streamlit UIst.title("🖌️ AI Image Generator")st.subheader("Generate images from text prompts!")# Input promptprompt = st.text_input("Enter your image prompt: e.g.'astronaut on a bike'", "")# Generate buttonif st.button("Generate Image"):if prompt.strip():with st.spinner("Generating image... Please wait."):try:# Query the Hugging Face APIimage_bytes = query_hf_api(prompt)image = Image.open(io.BytesIO(image_bytes))# Display the generated imagest.image(image, caption="Generated Image", use_container_width=True) # Updated hereexcept Exception as e:st.error(f"Error: {str(e)}")else:st.error("Please enter a prompt to generate an image.")st.caption("Made with ❤️ by Sumit Yadav. Credits to 🤗 Spaces for Hosting this. ")2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687882 unmodified linesimport iofrom utils import query_hf_api# Set page configurationst.set_page_config(page_title="AI Image Generator",page_icon="🎨",layout="centered",initial_sidebar_state="collapsed",)# App Headerst.title("🎨 AI Image Generator")st.markdown("""<style>.main-title {font-size: 2.5rem;color: #4CAF50;font-weight: bold;text-align: center;}.sub-title {font-size: 1.2rem;color: #555;text-align: center;margin-bottom: 20px;}.footer {font-size: 0.9rem;color: #888;text-align: center;margin-top: 50px;}</style>""",unsafe_allow_html=True,)st.markdown('<h1 class="main-title">AI-Powered Image Generator</h1>', unsafe_allow_html=True)st.markdown('<h3 class="sub-title">Generate images from your imagination!</h3>', unsafe_allow_html=True)# Input promptprompt = st.text_input("Enter your image prompt:",placeholder="e.g., 'Astronaut riding a bike on Mars at sunset'",)# Generate buttonif st.button("✨ Generate Image"):if prompt.strip():with st.spinner("🖌️ Generating your masterpiece... Please wait!"):try:# Query the Hugging Face APIimage_bytes = query_hf_api(prompt)image = Image.open(io.BytesIO(image_bytes)).convert("RGB") # Ensure it's RGB for JPEG# Display the generated imagest.image(image, caption="Generated Image", use_container_width=True)# Save the image as JPEG to a BytesIO bufferbuffer = io.BytesIO()image.save(buffer, format="JPEG", quality=95)buffer.seek(0)# Add a download buttonst.download_button(label="📥 Download Image",data=buffer,file_name="generated_image.jpg",mime="image/jpeg",)except Exception as e:st.error(f"🚨 Error: {str(e)}")else:st.warning("Please enter a prompt to generate an image.")# Footerst.markdown("""<div class="footer">Made with ❤️ by <b>Sumit Yadav</b>. Credits to 🤗 Spaces for hosting this app.</div>""",unsafe_allow_html=True,)
app.py+70-11