SpyroSigma commited on
Commit
51e38ec
·
verified ·
1 Parent(s): f96dea1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -4
app.py CHANGED
@@ -1,7 +1,48 @@
1
- # Load model directly
2
  import streamlit as st
3
- from transformers import AutoModel
4
- model = AutoModel.from_pretrained("liminerity/bitmap-mistral-M7-slerp-alpaca-70m-gguf")
 
 
 
 
 
 
 
 
 
 
5
 
6
  st.title("BitMap Generator")
7
- st.text(model)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from llama_cpp import Llama
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Initialize the model (only once)
7
+ @st.cache_resource
8
+ def load_model():
9
+ return Llama(
10
+ model_path="models/bitmap-mistral-M7-slerp-alpaca-70m.gguf",
11
+ n_ctx=2048,
12
+ n_threads=4
13
+ )
14
 
15
  st.title("BitMap Generator")
16
+
17
+ # Input text prompt
18
+ prompt = st.text_input("Enter your prompt for the bitmap:", "A simple circle")
19
+
20
+ if st.button("Generate Bitmap"):
21
+ if prompt:
22
+ # Generate the bitmap description
23
+ llm = load_model()
24
+ response = llm(
25
+ f"Generate a 32x32 bitmap array using 0s and 1s that represents {prompt}. "
26
+ "Only output the array, no other text.",
27
+ max_tokens=2048,
28
+ temperature=0.7
29
+ )
30
+
31
+ # Convert the response to a bitmap
32
+ try:
33
+ # Parse the response to get just the array
34
+ array_text = response['choices'][0]['text'].strip()
35
+ # Convert string to numpy array
36
+ bitmap = np.array([list(map(int, row.strip('[] ').split()))
37
+ for row in array_text.split('\n') if row.strip()])
38
+
39
+ # Scale up the bitmap for better visibility
40
+ scaled_bitmap = np.kron(bitmap, np.ones((10, 10)))
41
+
42
+ # Create an image from the array
43
+ img = Image.fromarray(np.uint8(scaled_bitmap * 255))
44
+
45
+ # Display the image
46
+ st.image(img, caption=f"Generated bitmap for: {prompt}")
47
+ except Exception as e:
48
+ st.error(f"Error creating bitmap: {str(e)}")