CoolFace
Apppublic

SpyroSigma/bitmap

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py51 linesDownload Raw Back to root
1import streamlit as st2from llama_cpp import Llama3from PIL import Image4import numpy as np5from transformers import AutoModel6model = AutoModel.from_pretrained("liminerity/bitmap-mistral-M7-slerp-alpaca-70m-gguf")7 8# Initialize the model (only once)9@st.cache_resource10def load_model():11    return Llama(12        model_path=model,13        n_ctx=2048,14        n_threads=415    )16 17st.title("BitMap Generator")18 19# Input text prompt20prompt = st.text_input("Enter your prompt for the bitmap:", "A simple circle")21 22if st.button("Generate Bitmap"):23    if prompt:24        # Generate the bitmap description25        llm = load_model()26        response = llm(27            f"Generate a 64x64 bitmap array using 0s and 1s that represents {prompt}. "28            "Only output the array, no other text.",29            max_tokens=2048,30            temperature=0.731        )32        33        # Convert the response to a bitmap34        try:35            # Parse the response to get just the array36            array_text = response['choices'][0]['text'].strip()37            # Convert string to numpy array38            bitmap = np.array([list(map(int, row.strip('[] ').split()))39                             for row in array_text.split('\n') if row.strip()])40            41            # Scale up the bitmap for better visibility42            scaled_bitmap = np.kron(bitmap, np.ones((10, 10)))43            44            # Create an image from the array45            img = Image.fromarray(np.uint8(scaled_bitmap * 255))46            47            # Display the image48            st.image(img, caption=f"Generated bitmap for: {prompt}")49        except Exception as e:50            st.error(f"Error creating bitmap: {str(e)}")51