Spaces:
Sleeping
Sleeping
import gradio as gr | |
from generate_text import generate_text_bitmap | |
from combine_bitmaps import combine_bitmaps | |
from simulator import simulate_bitmap | |
from PIL import Image | |
import os | |
images = [] | |
def get_path_from_object(files): | |
file_names = [f.name for f in files] | |
print(file_names) | |
return file_names[0] | |
def create_bitmap(linien_bitmap_object, text): | |
# generates bitmap from given text and saves it to tmp/font.bmp | |
generate_text_bitmap(text) | |
text_image = Image.open("tmp/font.bmp") | |
linien_image = Image.open(get_path_from_object(linien_bitmap_object)) | |
combine_bitmaps(linien_image, text_image) | |
combined_bitmap = Image.open("tmp/combined_bitmap.bmp") | |
# adds pixels in betweeen and saves result to tmp/simulated_bitmap.bmp | |
simulate_bitmap(combined_bitmap) | |
# adds simulated bitmap to gallery | |
os.rename( | |
"tmp/simulated_bitmap.bmp", | |
"tmp/simulated_bitmap_" + text + "_" + str(len(images)) + ".bmp", | |
) | |
images.append("tmp/simulated_bitmap_" + text + "_" + str(len(images)) + ".bmp") | |
return images | |
""" demo = gr.Interface( | |
fn=create_bitmap, | |
inputs=["files", "text"], | |
outputs=["gallery"], | |
) """ | |
with gr.Blocks() as demo: | |
files = gr.Files() | |
text = gr.Textbox(lines=1) | |
btn = gr.Button("Generate") | |
gallery = gr.Gallery(object_fit="scale-down", height="auto", columns=5) | |
btn.click(create_bitmap, [files, text], gallery) | |
if __name__ == "__main__": | |
demo.launch(inbrowser=True) | |