m4k1-dev commited on
Commit ·
5405406
1
Parent(s): 6bab4cf
add reset route
Browse files- README.md +1 -0
- app/app.py +17 -0
README.md
CHANGED
|
@@ -11,6 +11,7 @@ The `main` branch contains a template for a container that will spin up an API t
|
|
| 11 |
3. `/upload-audio/` : Upload audio files, save to noisy audio directory
|
| 12 |
4. `/enhance/` : Initialize model, enhance audio files, save to enhanced audio directory
|
| 13 |
5. `/download-enhanced/` : Download enhanced audio files
|
|
|
|
| 14 |
|
| 15 |
To add your own model to this template, there are a few things that a miner must do:
|
| 16 |
|
|
|
|
| 11 |
3. `/upload-audio/` : Upload audio files, save to noisy audio directory
|
| 12 |
4. `/enhance/` : Initialize model, enhance audio files, save to enhanced audio directory
|
| 13 |
5. `/download-enhanced/` : Download enhanced audio files
|
| 14 |
+
6. `/reset/` : Remove all existing audio files for another batch of enhancement
|
| 15 |
|
| 16 |
To add your own model to this template, there are a few things that a miner must do:
|
| 17 |
|
app/app.py
CHANGED
|
@@ -78,6 +78,7 @@ class ModelAPI:
|
|
| 78 |
self.app.post("/upload-audio/")(self.upload_audio)
|
| 79 |
self.app.post("/enhance/")(self.enhance_audio)
|
| 80 |
self.app.get("/download-enhanced/")(self.download_enhanced)
|
|
|
|
| 81 |
|
| 82 |
def get_status(self):
|
| 83 |
try:
|
|
@@ -152,6 +153,22 @@ class ModelAPI:
|
|
| 152 |
except Exception as e:
|
| 153 |
# Log the error if needed, and raise an HTTPException to inform the client
|
| 154 |
raise fastapi.HTTPException(status_code=500, detail=f"An error occurred while creating the download file: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
def run(self):
|
| 157 |
|
|
|
|
| 78 |
self.app.post("/upload-audio/")(self.upload_audio)
|
| 79 |
self.app.post("/enhance/")(self.enhance_audio)
|
| 80 |
self.app.get("/download-enhanced/")(self.download_enhanced)
|
| 81 |
+
self.app.get("/reset/")(self.reset)
|
| 82 |
|
| 83 |
def get_status(self):
|
| 84 |
try:
|
|
|
|
| 153 |
except Exception as e:
|
| 154 |
# Log the error if needed, and raise an HTTPException to inform the client
|
| 155 |
raise fastapi.HTTPException(status_code=500, detail=f"An error occurred while creating the download file: {str(e)}")
|
| 156 |
+
|
| 157 |
+
def reset(self):
|
| 158 |
+
"""
|
| 159 |
+
Removes all audio files in preparation for another batch of enhancement.
|
| 160 |
+
"""
|
| 161 |
+
for directory in [self.noisy_audio_path, self.enhanced_audio_path]:
|
| 162 |
+
if not os.path.isdir(directory):
|
| 163 |
+
continue
|
| 164 |
+
|
| 165 |
+
for filename in os.listdir(directory):
|
| 166 |
+
filepath = os.path.join(directory, filename)
|
| 167 |
+
if os.path.isfile(filepath):
|
| 168 |
+
try:
|
| 169 |
+
os.remove(filepath)
|
| 170 |
+
except Exception as e:
|
| 171 |
+
print(f"Error removing {filepath}: {e}")
|
| 172 |
|
| 173 |
def run(self):
|
| 174 |
|