Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,37 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
| 2 |
import os
|
| 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 |
-
print(f"Loaded {len(reports)} reports.")
|
| 37 |
-
print(f"Loaded {len(medical_history)} medical history records.")
|
| 38 |
-
|
| 39 |
-
# Return all the data for further processing
|
| 40 |
-
return users, appointments, prescriptions, reports, medical_history
|
| 41 |
-
|
| 42 |
-
def main():
|
| 43 |
-
print("Initializing MediConsult App...")
|
| 44 |
-
|
| 45 |
-
# Load all data from CSV files
|
| 46 |
-
users, appointments, prescriptions, reports, medical_history = load_all_data()
|
| 47 |
-
|
| 48 |
-
# Additional logic to handle the application workflow
|
| 49 |
-
# For example, managing user authentication, processing appointment requests, etc.
|
| 50 |
-
|
| 51 |
-
if __name__ == "__main__":
|
| 52 |
-
main()
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
+
import shutil
|
| 4 |
import os
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
# Use absolute path for the upload directory
|
| 10 |
+
BASE_DIR = Path(__file__).resolve().parent
|
| 11 |
+
UPLOAD_DIR = BASE_DIR / "uploads"
|
| 12 |
+
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
| 13 |
+
|
| 14 |
+
@app.post("/uploadfile/")
|
| 15 |
+
async def create_upload_file(file: UploadFile = File(...)):
|
| 16 |
+
# Sanitize the file name
|
| 17 |
+
filename = os.path.basename(file.filename)
|
| 18 |
+
file_location = UPLOAD_DIR / filename
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
with open(file_location, "wb") as buffer:
|
| 22 |
+
shutil.copyfileobj(file.file, buffer)
|
| 23 |
+
return {"info": f"file '{filename}' saved at '{file_location}'"}
|
| 24 |
+
except Exception as e:
|
| 25 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 26 |
+
|
| 27 |
+
@app.get("/")
|
| 28 |
+
async def main():
|
| 29 |
+
content = """
|
| 30 |
+
<body>
|
| 31 |
+
<form action="/uploadfile/" enctype="multipart/form-data" method="post">
|
| 32 |
+
<input name="file" type="file">
|
| 33 |
+
<input type="submit">
|
| 34 |
+
</form>
|
| 35 |
+
</body>
|
| 36 |
+
"""
|
| 37 |
+
return HTMLResponse(content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|