-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstreamlit_.py
164 lines (135 loc) · 5.95 KB
/
streamlit_.py
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from io import StringIO
from pathlib import Path
import streamlit as st
from detect_FFA import detect
# from detect_DMSHN import detect
import os
import sys
import cv2
import numpy as np
import argparse
from PIL import Image
if __name__ == '__main__':
st.image('header2.png')
st.subheader('1. 使用')
st.write('·您可以使用左侧来进行文件选择并上传')
code1 = '''You can use the left side to select and upload files'''
st.video('introduction.mp4')
st.code(code1, language='bash')
st.subheader('2. 功能')
st.write('·云端仅支持CPU计算,推理时间较久')
code2 = 'Vision tasks: dehaze, denoisy, derain, low_light_enhencement'
st.code(code2, language='bash')
st.subheader('3. 运行区')
parser = argparse.ArgumentParser()
parser.add_argument('--source', type=str,
default='', help='source')
opt = parser.parse_args()
source_button= ("图片上传", "视频上传" )
source_index = st.sidebar.selectbox("选择输入", range(
len(source_button)), format_func=lambda x: source_button[x])
if source_index == 0:
uploaded_file = st.sidebar.file_uploader("上传图片", type=['png', 'jpeg', 'jpg'])
if uploaded_file is not None:
is_valid = True
with st.spinner(text='资源加载中...'):
st.sidebar.image(uploaded_file)
picture = Image.open(uploaded_file)
picture = picture.save(f'data/images/{uploaded_file.name}')
opt.source = f'data/images/{uploaded_file.name}'
else:
is_valid = False
else:
uploaded_file = st.sidebar.file_uploader("上传视频", type=['mp4'])
if uploaded_file is not None:
is_valid = True
with st.spinner(text='资源加载中...'):
st.sidebar.video(uploaded_file)
with open(os.path.join("data", "videos", uploaded_file.name), "wb") as f:
f.write(uploaded_file.getbuffer())
opt.source = f'data/videos/{uploaded_file.name}'
else:
is_valid = False
if is_valid:
st.write('tips:若视频无法播放,请点击下载~')
option = st.selectbox("文件加载成功", ['请选择任务', '视觉去雾', '视觉去雨', '视觉去噪', '低光照增强'])
if option == "视觉去雨":
detect(opt, task = 'derain')
if source_index == 0:
with open('runs/detect/clean.jpg', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.jpg',
)
with st.spinner(text='Preparing Images'):
st.image('runs/detect/clean.jpg')
else:
with open('runs/detect/clean.mp4', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.mp4',
)
with st.spinner(text='Preparing Images'):
st.video('runs/detect/clean.mp4')
if option == "视觉去噪":
detect(opt, task = 'denoisy')
if source_index == 0:
with open('runs/detect/clean.jpg', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.jpg',
)
with st.spinner(text='Preparing Images'):
st.image('runs/detect/clean.jpg')
else:
with open('runs/detect/clean.mp4', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.mp4',
)
with st.spinner(text='Preparing Video'):
st.video('runs/detect/clean.mp4')
if option == "视觉去雾":
detect(opt, task='dehaze')
if source_index == 0:
with open('runs/detect/clean.jpg', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.jpg',
)
with st.spinner(text='Preparing Images'):
st.image('runs/detect/clean.jpg')
else:
with open('runs/detect/clean.mp4', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.mp4',
)
with st.spinner(text='Preparing Video'):
st.video('runs/detect/clean.mp4')
if option == "低光照增强":
detect(opt, task='enhencement')
if source_index == 0:
with open('runs/detect/clean.jpg', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.jpg',
)
with st.spinner(text='Preparing Images'):
st.image('runs/detect/clean.jpg')
else:
with open('runs/detect/clean.mp4', "rb") as file:
btn = st.download_button(
label="点击下载",
data=file,
file_name='clean.mp4',
)
with st.spinner(text='Preparing Video'):
st.video('runs/detect/clean.mp4')