feat: some not working tabs

This commit is contained in:
Artemy 2023-04-15 19:36:31 +03:00
parent f338f7b5c9
commit efcd1ccbac
4 changed files with 128 additions and 90 deletions

2
.gitignore vendored
View file

@ -150,3 +150,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
output

137
app.py
View file

@ -1,98 +1,55 @@
import datetime
import gradio as gr
from PIL import Image, ImageChops
import os
from tqdm import tqdm
def impluser(dir, method):
files = os.listdir(dir)
files = list(map(lambda x: os.path.join(dir, x), files))
files = list(filter(lambda x: x.endswith(".png"), files))
if method == "denoise":
img = denoise(files)
elif method == "startracks":
img = startracks(files)
elif method == "noise extractor":
img = noise_extractor(files)
elif method == "untrack":
img = untrack(files)
name = generate_name()
img.save(name)
return [name]
def generate_name():
# if not exists output create it
if not os.path.exists("./output"):
os.mkdir("./output")
return f"./output/{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.png"
def denoise(files):
bias = 1
image = Image.open(files[0])
for file in tqdm(files):
alpha = 1/bias
im2 = Image.open(file)
im3 = Image.blend(image, im2, alpha)
image = im3
bias += 1
return image
def startracks(files):
image = Image.open(files[0])
for file in tqdm(files):
im2 = Image.open(file)
im3 = ImageChops.lighter(image, im2)
image = im3
return image
def noise_extractor(files):
image = Image.open(files[0])
for file in tqdm(files, unit=' images'):
im2 = Image.open(file)
im3 = ImageChops.difference(image, im2)
image = im3
return image
def untrack(files):
image = Image.open(files[0])
for file in tqdm(files, unit=' images'):
im2 = Image.open(file)
im3 = ImageChops.darker(image, im2)
image = im3
return image
from processing.stacking import stacking
with gr.Blocks() as app:
with gr.Row():
with gr.Column():
directory = gr.Textbox(
placeholder="A directory on the same machine where the server is running.", lines=1, label="Directory")
methods = gr.Dropdown(
choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method")
submit = gr.Button("Submit")
with gr.Tab("Stacking"):
gr.Markdown("Stacking images.")
with gr.Row():
with gr.Column():
directory = gr.Text(
placeholder="A directory with many images of the same size", lines=1, label="Directory")
methods = gr.Dropdown(
choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method")
submit = gr.Button("Submit")
with gr.Column():
output = gr.Gallery()
with gr.Column():
output = gr.Gallery()
submit.click(stacking, inputs=[
directory, methods], outputs=[output])
with gr.Tab("Bulk processing"):
gr.Markdown(
"Mass processing of images one at a time and saving to video if needed. # **WIP, not working**")
with gr.Row():
with gr.Column():
directory = gr.Text(
placeholder="A directory with many images of the same size", lines=1, label="Directory")
methods = gr.Dropdown(
choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method")
submit = gr.Button("Submit")
with gr.Tab("Video to images"):
gr.Markdown(
"Convert video to images. # **WIP, not working**")
with gr.Row():
with gr.Column():
video = gr.Video(label="Video")
format = gr.Radio(
choices=["png", "jpg"], value="png", label="Format of image")
submit = gr.Button("Submit")
with gr.Tab("Images to video"):
gr.Markdown("Convert images to video. # **WIP, not working**")
with gr.Row():
with gr.Column():
directory = gr.Text(
placeholder="A directory with many images of the same size", lines=1, label="Directory")
fps = gr.Number(label="FPS")
submit = gr.Button("Submit")
submit.click(impluser, inputs=[directory, methods], outputs=[output])
app.launch()

49
methods/stack_methods.py Normal file
View file

@ -0,0 +1,49 @@
from PIL import Image, ImageChops
from tqdm import tqdm
def denoise(files):
bias = 1
image = Image.open(files[0])
for file in tqdm(files):
alpha = 1/bias
im2 = Image.open(file)
im3 = Image.blend(image, im2, alpha)
image = im3
bias += 1
return image
def startracks(files):
image = Image.open(files[0])
for file in tqdm(files):
im2 = Image.open(file)
im3 = ImageChops.lighter(image, im2)
image = im3
return image
def noise_extractor(files):
image = Image.open(files[0])
for file in tqdm(files, unit=' images'):
im2 = Image.open(file)
im3 = ImageChops.difference(image, im2)
image = im3
return image
def untrack(files):
image = Image.open(files[0])
for file in tqdm(files, unit=' images'):
im2 = Image.open(file)
im3 = ImageChops.darker(image, im2)
image = im3
return image

30
processing/stacking.py Normal file
View file

@ -0,0 +1,30 @@
from methods.stack_methods import denoise, startracks, noise_extractor, untrack
import os
import datetime
def generate_name():
os.makedirs("./output/stacked", exist_ok=True)
return f"./output/stacked/{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.png"
def stacking(dir, method):
files = os.listdir(dir)
files = list(map(lambda x: os.path.join(dir, x), files))
files = list(filter(lambda x: x.endswith(".png"), files))
if method == "denoise":
img = denoise(files)
elif method == "startracks":
img = startracks(files)
elif method == "noise extractor":
img = noise_extractor(files)
elif method == "untrack":
img = untrack(files)
name = generate_name()
img.save(name)
return [name]