|
import streamlit as st |
|
import base64 |
|
import os.path |
|
import os |
|
import cv2 |
|
import random |
|
|
|
os.system("ls") |
|
col1, col2 = st.columns(2) |
|
|
|
title = "Melhoria de imagens" |
|
st.title(title) |
|
os.system("ls") |
|
description = "Sistema para automação。" |
|
st.header(description) |
|
article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>clone from akhaliq@huggingface with little change</a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>" |
|
|
|
|
|
uploaded_file = st.file_uploader("Choose a file") |
|
if uploaded_file is not None: |
|
|
|
bytes_data = uploaded_file.getvalue() |
|
st.video(bytes_data) |
|
os.system("rm -R /tmp/*") |
|
os.system("mkdir /tmp/_input") |
|
os.system("mkdir /tmp/_output") |
|
os.system("mkdir /tmp/_outputf") |
|
os.system("mkdir /tmp/videoSaida") |
|
with open("/tmp/inputvideo", "wb") as binary_file: |
|
binary_file.write(bytes_data) |
|
vcap = cv2.VideoCapture('/tmp/inputvideo') |
|
width=0 |
|
height=0 |
|
if vcap.isOpened(): |
|
|
|
width = vcap.get(3) |
|
height = vcap.get(4) |
|
|
|
st.write(str(width)+"x"+str(height)) |
|
fps = vcap.get(5) |
|
st.write(str(fps)+" fps") |
|
@st.experimental_memo(suppress_st_warning=True) |
|
def chamada(): |
|
|
|
|
|
percent_complete=0 |
|
my_bar = st.progress(0) |
|
percent_complete= percent_complete+ 10 |
|
with col1: |
|
my_bar.progress(percent_complete ) |
|
|
|
|
|
|
|
vcap = cv2.VideoCapture('/tmp/inputvideo') |
|
width=0 |
|
height=0 |
|
if vcap.isOpened(): |
|
|
|
width = vcap.get(3) |
|
height = vcap.get(4) |
|
fps = vcap.get(5) |
|
|
|
|
|
os.system("ffmpeg -i /tmp/inputvideo -compression_level 10 -pred mixed -pix_fmt rgb24 -sws_flags +accurate_rnd+full_chroma_int -s "+str(int(width/2))+"x"+str(int(height/2))+" -r 29.97 /tmp/_input/imagem-%4d.png") |
|
percent_complete= percent_complete+ 30 |
|
with col1: |
|
my_bar.progress(percent_complete ) |
|
|
|
input_img = cv2.imread("/tmp/_input/imagem-0002.png" , cv2.IMREAD_COLOR) |
|
input_img= cv2.cvtColor(input_img,cv2.COLOR_BGR2RGB) |
|
with col1: |
|
st.image(input_img) |
|
|
|
os.system("ls /tmp/_input") |
|
if 'myVar' not in globals(): |
|
myVar="" |
|
|
|
with col2: |
|
with st.spinner('Wait for it...'): |
|
|
|
os.system("python3 inference_gfpgan.py -i /tmp/_input -o /tmp/_output -v 1.3 -s 2") |
|
with col1: |
|
percent_complete= percent_complete+ 30 |
|
my_bar.progress(percent_complete ) |
|
|
|
os.system("ls /tmp/_output") |
|
os.system("echo ----") |
|
os.system("ls /tmp/_output/cmp") |
|
os.system("echo ----") |
|
os.system("ls /tmp/_output/restored_imgs") |
|
os.system("echo ----") |
|
|
|
|
|
|
|
|
|
os.system("ffmpeg -y -r 29.97 -f image2 -i /tmp/_output/restored_imgs/imagem-%4d.png -pix_fmt yuv420p /tmp/videoSaida/output.mp4") |
|
|
|
os.system("ls /tmp/videoSaida") |
|
|
|
with col1: |
|
|
|
percent_complete= percent_complete+ 30 |
|
my_bar.progress(percent_complete ) |
|
with col2: |
|
with open("/tmp/videoSaida/output.mp4", "rb") as file: |
|
st.video(file) |
|
|
|
btn = st.download_button( |
|
|
|
label="Download video", |
|
|
|
data=file, |
|
|
|
file_name="output.mp4", |
|
|
|
mime="video/mp4" |
|
|
|
) |
|
|
|
|
|
|
|
|
|
with col2: |
|
|
|
input_img = cv2.imread("/tmp/_output/restored_imgs/imagem-0002.png" , cv2.IMREAD_COLOR) |
|
input_img= cv2.cvtColor(input_img,cv2.COLOR_BGR2RGB) |
|
|
|
st.image(input_img) |
|
exec=False |
|
|
|
load = st.checkbox("load") |
|
|
|
if load: |
|
chamada() |
|
|
|
|
|
exec=True |
|
|