Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Light cleanup of unused code and comments
Browse files
app.py
CHANGED
|
@@ -62,17 +62,6 @@ MULTI_DEMO_PATHS = [
|
|
| 62 |
|
| 63 |
torch.classes.__path__ = [os.path.join(torch.__path__[0], torch.classes.__file__)]
|
| 64 |
|
| 65 |
-
isGPU = torch.cuda.is_available()
|
| 66 |
-
device = torch.device("cuda" if isGPU else "cpu")
|
| 67 |
-
print(f"Using {device}")
|
| 68 |
-
|
| 69 |
-
if ENABLE_DENOISE:
|
| 70 |
-
from df import init_df
|
| 71 |
-
dfModel, dfState, _ = init_df(model_base_dir="DeepFilterNet3")
|
| 72 |
-
dfModel.to(device)
|
| 73 |
-
else:
|
| 74 |
-
dfModel = dfState = None
|
| 75 |
-
|
| 76 |
pipeline = Sonogram()
|
| 77 |
st.session_state.pipeline = pipeline
|
| 78 |
|
|
@@ -157,17 +146,22 @@ uploaded_file_paths = st.file_uploader(
|
|
| 157 |
key=f"uploader_{st.session_state.uploader_key}",
|
| 158 |
)
|
| 159 |
|
|
|
|
| 160 |
temp_dir = tempfile.mkdtemp()
|
| 161 |
|
|
|
|
| 162 |
if uploaded_file_paths:
|
| 163 |
for uploaded_file in uploaded_file_paths:
|
|
|
|
| 164 |
if not uploaded_file.name.lower().endswith(SUPPORTED_FILE_TYPES):
|
| 165 |
st.error(f"File must be of type: {SUPPORTED_FILE_TYPES}")
|
| 166 |
continue
|
|
|
|
| 167 |
fname = uploaded_file.name
|
| 168 |
path = os.path.join(temp_dir, fname)
|
| 169 |
with open(path, "wb") as f:
|
| 170 |
f.write(uploaded_file.getvalue())
|
|
|
|
| 171 |
if fname not in st.session_state.file_names:
|
| 172 |
register_file(fname)
|
| 173 |
st.session_state.file_paths[fname] = path
|
|
|
|
| 62 |
|
| 63 |
torch.classes.__path__ = [os.path.join(torch.__path__[0], torch.classes.__file__)]
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
pipeline = Sonogram()
|
| 66 |
st.session_state.pipeline = pipeline
|
| 67 |
|
|
|
|
| 146 |
key=f"uploader_{st.session_state.uploader_key}",
|
| 147 |
)
|
| 148 |
|
| 149 |
+
# Make temp directory
|
| 150 |
temp_dir = tempfile.mkdtemp()
|
| 151 |
|
| 152 |
+
# If files have been uploaded
|
| 153 |
if uploaded_file_paths:
|
| 154 |
for uploaded_file in uploaded_file_paths:
|
| 155 |
+
# Check for supported file types via extension
|
| 156 |
if not uploaded_file.name.lower().endswith(SUPPORTED_FILE_TYPES):
|
| 157 |
st.error(f"File must be of type: {SUPPORTED_FILE_TYPES}")
|
| 158 |
continue
|
| 159 |
+
# Save file locally to server
|
| 160 |
fname = uploaded_file.name
|
| 161 |
path = os.path.join(temp_dir, fname)
|
| 162 |
with open(path, "wb") as f:
|
| 163 |
f.write(uploaded_file.getvalue())
|
| 164 |
+
# Add file to list of known files
|
| 165 |
if fname not in st.session_state.file_names:
|
| 166 |
register_file(fname)
|
| 167 |
st.session_state.file_paths[fname] = path
|