File size: 5,530 Bytes
e56410f
006270c
c1ce44f
24e97b8
8442b36
6123f94
20ab9f7
92ed922
7b94e89
96c8c19
07a6275
 
 
 
 
 
603119d
2d26079
603119d
 
 
 
 
83ea464
 
 
 
 
2fb0f4c
c2c91b6
2fb0f4c
2d26079
 
 
 
a3cc716
 
2d26079
 
a3cc716
9e99859
b1647df
b6c06f2
83ea464
 
1b3ea2c
 
07a6275
7b94e89
 
6a2fa62
b1647df
6a2fa62
2fb0f4c
4b9ee7c
 
 
2d26079
a3cc716
 
 
a4f8216
85ce803
efecf8d
07a6275
7b94e89
 
b1647df
a8dc86d
642303e
7b94e89
 
07a6275
2fb0f4c
642303e
 
b1647df
7b94e89
 
642303e
483e04d
7b94e89
 
 
07a6275
2fb0f4c
642303e
2fb0f4c
642303e
a8dc86d
642303e
 
b1647df
 
642303e
efecf8d
85ce803
2fb0f4c
642303e
7b94e89
b1647df
7b94e89
 
 
2fb0f4c
812e077
07a6275
642303e
 
 
 
 
 
ff19de2
642303e
 
 
 
 
 
 
 
5253d3d
b1647df
2fb0f4c
7b94e89
642303e
7b94e89
642303e
 
b6c06f2
 
 
 
642303e
96c8c19
18e65bf
1306203
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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:
    # To read file as bytes:
    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') # 0=camera
    width=0
    height=0
    if vcap.isOpened(): 
              # get vcap property 
              width  = vcap.get(3)   # float `width`
              height = vcap.get(4)  # float `height`
              
              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 )    
       #exec=True 
#           st.write("ffmpeg separando imagens")
       #if not os.path.isfile("./_input/imagem-0001.png"):
          vcap = cv2.VideoCapture('/tmp/inputvideo') # 0=camera
          width=0
          height=0
          if vcap.isOpened(): 
              # get vcap property 
              width  = vcap.get(3)   # float `width`
              height = vcap.get(4)  # float `height`
              fps = vcap.get(5)

        #  os.system("ffmpeg -i /tmp/inputvideo -vn -acodec copy /tmp/inputvideo.acc")
          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 )   
 #          st.write("testando imagem")
          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=""
  #        st.write("melhorando faces")
          with col2:
           with st.spinner('Wait for it...'):
             # os.system("pip install git+https://github.com/TencentARC/GFPGAN.git")
                    os.system("python3 inference_gfpgan.py -i /tmp/_input -o /tmp/_output -v 1.4 -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 ----")
#          s 1480x2560
       #   with col1:
   #        st.write("recompilando video")
          #ffmpeg -r 60 -f image2 -s 1920x1080 -i _output/restored_imgs/imagem-%4d.png   -pix_fmt yuv420p ./videoSaida/output.mp4
          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("ffmpeg -i /tmp/videoSaida/outputp1.mp4 -i /tmp/inputvideo.acc -c:v copy -c:a aac /tmp/output.mp4")
          os.system("ls /tmp/videoSaida")
          #st.video("./videoSaida/output.mp4" )
          with col1:
        #   st.write("preparando para download do video")
           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"
          
                    )
          #st.download_button("download video", data, file_name='output.mp4', mime='video/mp4',)
          #stremio
          #input_img = cv2.imread("./_output/cmp/imagem-0001_0000.png" , cv2.IMREAD_COLOR)
          #input_img = cv2.imread("./_output/cmp/imagem-0001_0000.png" , cv2.IMREAD_COLOR)
          with col2:
         #  st.write("demonstrando imagem restaurada")
           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
       #return Image.fromarray(restored_faces[0][:,:,::-1])
load = st.checkbox("load")

if load:
       chamada()
   
#st.button('Imagem',on_click=inference)
exec=True