nft launchplace for meme agents
To upload files, please first save the app
import streamlit as st
from sqlalchemy import create_engine, Column, Integer, String, Float
from sqlalchemy.orm import DeclarativeBase, Session
from datetime import datetime
import random
from PIL import Image, ImageDraw, ImageFont
import io
# Database setup
class Base(DeclarativeBase):
pass
class NFT(Base):
__tablename__ = "nfts"
id = Column(Integer, primary_key=True)
name = Column(String)
description = Column(String)
price = Column(Float)
owner = Column(String)
image_data = Column(String)
engine = create_engine("sqlite:///nft_marketplace.sqlite")
Base.metadata.create_all(bind=engine)
def generate_meme_agent_image(name):
# Create a simple image with text
img = Image.new('RGB', (400, 400), color='white')
d = ImageDraw.Draw(img)
# Add random background color
bg_color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
d.rectangle([(0, 0), (400, 400)], fill=bg_color)
# Add agent name
d.text((50, 180), f"Agent\n{name}", fill='white', align='center', spacing=10)
# Convert to bytes
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
return img_byte_arr
st.title("🎨 Meme Agent NFT Launchpad")
# Sidebar for creation
with st.sidebar:
st.header("Create New NFT")
nft_name = st.text_input("Agent Name")
nft_description = st.text_area("Description")
nft_price = st.number_input("Price (ETH)", min_value=0.0, step=0.1)
if st.button("Create NFT"):
if nft_name and nft_description and nft_price > 0:
img_data = generate_meme_agent_image(nft_name)
with Session(engine) as session:
new_nft = NFT(
name=nft_name,
description=nft_description,
price=nft_price,
owner="marketplace",
image_data=str(img_data)
)
session.add(new_nft)
session.commit()
st.success("NFT Created Successfully!")
st.balloons()
# Main marketplace display
st.header("Available NFTs")
with Session(engine) as session:
nfts = session.query(NFT).filter_by(owner="marketplace").all()
if not nfts:
st.info("No NFTs available in the marketplace yet!")
for nft in nfts:
with st.container():
col1, col2 = st.columns([1, 2])
with col1:
try:
img_data = eval(nft.image_data)
st.image(img_data, caption=nft.name, use_column_width=True)
except:
st.write("Image unavailable")
with col2:
st.subheader(nft.name)
st.write(nft.description)
st.write(f"Price: {nft.price} ETH")
if st.button(f"Buy Now", key=f"buy_{nft.id}"):
with Session(engine) as session:
nft_to_update = session.query(NFT).filter_by(id=nft.id).first()
nft_to_update.owner = "user" # In a real app, this would be the user's wallet address
session.commit()
st.success("NFT Purchased Successfully!")
st.balloons()
st.rerun()
# Owned NFTs section
st.header("Your NFTs")
with Session(engine) as session:
owned_nfts = session.query(NFT).filter_by(owner="user").all()
if not owned_nfts:
st.info("You don't own any NFTs yet!")
for nft in owned_nfts:
with st.expander(f"{nft.name}"):
try:
img_data = eval(nft.image_data)
st.image(img_data, caption=nft.name, use_column_width=True)
except:
st.write("Image unavailable")
st.write(nft.description)
st.write(f"Purchased for: {nft.price} ETH")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?