import streamlit as st import qrcode import io # Set page title st.title("QR Code Generator") # Get user input url = st.text_input("Enter a URL or text to generate a QR code:") if url: # 1. Generate the QR code object # qrcode.make() returns a PIL image (specifically qrcode.image.pil.PilImage) img = qrcode.make(url) # 2. Create a BytesIO buffer to hold the image data in memory buffer = io.BytesIO() # 3. Save the image to the buffer in PNG format # This resolves the "TypeError: a bytes-like object is required" img.save(buffer, format="PNG") # 4. Display the image using the buffer # "use_container_width=True" resolves the Deprecation Warning st.image( buffer, caption="Generated QR Code", use_container_width=True ) else: st.info("Please enter text above to generate a QR code.")