Spaces:
Runtime error
Runtime error
Michael S. Trusov commited on
Commit ·
2a66de2
1
Parent(s): becc108
July 18 commit to Hugging Face 3:47pm
Browse files- app.py +32 -0
- fe5ad737-4460-4d52-97d8-5895668d9920_log_data.txt +2 -0
app.py
CHANGED
|
@@ -5,6 +5,34 @@ import time
|
|
| 5 |
import numpy as np
|
| 6 |
import json
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
qs = {}
|
| 9 |
|
| 10 |
theme = gr.themes.Base(
|
|
@@ -290,7 +318,11 @@ def log_message(param, session_id):
|
|
| 290 |
# Launching
|
| 291 |
# --------------------------------------------------------------------------------------------
|
| 292 |
|
|
|
|
|
|
|
| 293 |
app_inits()
|
|
|
|
|
|
|
| 294 |
demo.queue()
|
| 295 |
demo.launch(allowed_paths=["."], max_threads=40)
|
| 296 |
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import json
|
| 7 |
|
| 8 |
+
from fastapi import FastAPI, HTTPException
|
| 9 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 10 |
+
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
+
#--------------------------------------------------------------------------------
|
| 14 |
+
@app.get("/list-files")
|
| 15 |
+
def list_files(directory: str = ".", extension: str = ".txt"):
|
| 16 |
+
if not os.path.exists(directory):
|
| 17 |
+
raise HTTPException(status_code=404, detail="Directory not found")
|
| 18 |
+
|
| 19 |
+
files = [f for f in os.listdir(directory) if f.endswith(extension)]
|
| 20 |
+
return JSONResponse(content={"files": files})
|
| 21 |
+
|
| 22 |
+
@app.get("/download-file/{filename}")
|
| 23 |
+
def download_file(filename: str, directory: str = "."):
|
| 24 |
+
file_path = os.path.join(directory, filename)
|
| 25 |
+
if not os.path.exists(file_path):
|
| 26 |
+
raise HTTPException(status_code=404, detail="File not found")
|
| 27 |
+
return FileResponse(path=file_path, filename=filename)
|
| 28 |
+
|
| 29 |
+
def run_fastapi():
|
| 30 |
+
import uvicorn
|
| 31 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 32 |
+
|
| 33 |
+
#--------------------------------------------------------------------------------
|
| 34 |
+
|
| 35 |
+
|
| 36 |
qs = {}
|
| 37 |
|
| 38 |
theme = gr.themes.Base(
|
|
|
|
| 318 |
# Launching
|
| 319 |
# --------------------------------------------------------------------------------------------
|
| 320 |
|
| 321 |
+
import threading
|
| 322 |
+
|
| 323 |
app_inits()
|
| 324 |
+
|
| 325 |
+
threading.Thread(target=run_fastapi).start()
|
| 326 |
demo.queue()
|
| 327 |
demo.launch(allowed_paths=["."], max_threads=40)
|
| 328 |
|
fe5ad737-4460-4d52-97d8-5895668d9920_log_data.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2024-07-18 15:43:36: : -ENTRY- [query]: debug [params] [keyword] None
|
| 2 |
+
2024-07-18 15:43:36: : -EXIT- [query]: debug [params] [keyword] None
|