Hussein El-Hadidy commited on
Commit Β·
bfaa87e
1
Parent(s): 929690b
Connected To Database
Browse files- SkinBurns_Preprocessing.py +0 -0
- __pycache__/main.cpython-313.pyc +0 -0
- app.py +15 -6
- main.py +15 -6
SkinBurns_Preprocessing.py
ADDED
|
File without changes
|
__pycache__/main.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/main.cpython-313.pyc and b/__pycache__/main.cpython-313.pyc differ
|
|
|
app.py
CHANGED
|
@@ -17,11 +17,14 @@ try:
|
|
| 17 |
except Exception as e:
|
| 18 |
print("β MongoDB connection failed:", e)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# β
Cloudinary config
|
| 21 |
cloudinary.config(
|
| 22 |
cloud_name = "darumyfpl",
|
| 23 |
api_key = "493972437417214",
|
| 24 |
-
api_secret = "jjOScVGochJYA7IxDam7L4HU2Ig", # Replace
|
| 25 |
secure=True
|
| 26 |
)
|
| 27 |
|
|
@@ -30,21 +33,27 @@ cloudinary.config(
|
|
| 30 |
def greet_json():
|
| 31 |
return {"Hello": "World!"}
|
| 32 |
|
| 33 |
-
# β
MongoDB document count route
|
| 34 |
@app.get("/count")
|
| 35 |
def count_docs():
|
| 36 |
-
|
| 37 |
-
collection = db["my_collection"]
|
| 38 |
count = collection.count_documents({})
|
| 39 |
return {"document_count": count}
|
| 40 |
|
| 41 |
-
# β
Upload image to Cloudinary
|
| 42 |
@app.post("/cloudinary/upload")
|
| 43 |
async def upload_sample(file: UploadFile = File(...)):
|
| 44 |
try:
|
| 45 |
# Upload the file to Cloudinary
|
| 46 |
result = cloudinary.uploader.upload(file.file, public_id=file.filename)
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
return {"error": str(e)}
|
| 50 |
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
print("β MongoDB connection failed:", e)
|
| 19 |
|
| 20 |
+
# β
Use a shared database instance
|
| 21 |
+
db = client["El7a2ny"]
|
| 22 |
+
|
| 23 |
# β
Cloudinary config
|
| 24 |
cloudinary.config(
|
| 25 |
cloud_name = "darumyfpl",
|
| 26 |
api_key = "493972437417214",
|
| 27 |
+
api_secret = "jjOScVGochJYA7IxDam7L4HU2Ig", # Replace in production
|
| 28 |
secure=True
|
| 29 |
)
|
| 30 |
|
|
|
|
| 33 |
def greet_json():
|
| 34 |
return {"Hello": "World!"}
|
| 35 |
|
| 36 |
+
# β
MongoDB document count route for Images collection
|
| 37 |
@app.get("/count")
|
| 38 |
def count_docs():
|
| 39 |
+
collection = db["Images"]
|
|
|
|
| 40 |
count = collection.count_documents({})
|
| 41 |
return {"document_count": count}
|
| 42 |
|
| 43 |
+
# β
Upload image to Cloudinary and save URL to MongoDB
|
| 44 |
@app.post("/cloudinary/upload")
|
| 45 |
async def upload_sample(file: UploadFile = File(...)):
|
| 46 |
try:
|
| 47 |
# Upload the file to Cloudinary
|
| 48 |
result = cloudinary.uploader.upload(file.file, public_id=file.filename)
|
| 49 |
+
uploaded_url = result["secure_url"]
|
| 50 |
+
|
| 51 |
+
# Save image URL to MongoDB
|
| 52 |
+
collection = db["Images"]
|
| 53 |
+
doc = {"filename": file.filename, "url": uploaded_url}
|
| 54 |
+
collection.insert_one(doc)
|
| 55 |
+
|
| 56 |
+
return {"uploaded_url": uploaded_url}
|
| 57 |
except Exception as e:
|
| 58 |
return {"error": str(e)}
|
| 59 |
|
main.py
CHANGED
|
@@ -17,11 +17,14 @@ try:
|
|
| 17 |
except Exception as e:
|
| 18 |
print("β MongoDB connection failed:", e)
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# β
Cloudinary config
|
| 21 |
cloudinary.config(
|
| 22 |
cloud_name = "darumyfpl",
|
| 23 |
api_key = "493972437417214",
|
| 24 |
-
api_secret = "jjOScVGochJYA7IxDam7L4HU2Ig", # Replace
|
| 25 |
secure=True
|
| 26 |
)
|
| 27 |
|
|
@@ -30,21 +33,27 @@ cloudinary.config(
|
|
| 30 |
def greet_json():
|
| 31 |
return {"Hello": "World!"}
|
| 32 |
|
| 33 |
-
# β
MongoDB document count route
|
| 34 |
@app.get("/count")
|
| 35 |
def count_docs():
|
| 36 |
-
|
| 37 |
-
collection = db["my_collection"]
|
| 38 |
count = collection.count_documents({})
|
| 39 |
return {"document_count": count}
|
| 40 |
|
| 41 |
-
# β
Upload image to Cloudinary
|
| 42 |
@app.post("/cloudinary/upload")
|
| 43 |
async def upload_sample(file: UploadFile = File(...)):
|
| 44 |
try:
|
| 45 |
# Upload the file to Cloudinary
|
| 46 |
result = cloudinary.uploader.upload(file.file, public_id=file.filename)
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
return {"error": str(e)}
|
| 50 |
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
print("β MongoDB connection failed:", e)
|
| 19 |
|
| 20 |
+
# β
Use a shared database instance
|
| 21 |
+
db = client["El7a2ny"]
|
| 22 |
+
|
| 23 |
# β
Cloudinary config
|
| 24 |
cloudinary.config(
|
| 25 |
cloud_name = "darumyfpl",
|
| 26 |
api_key = "493972437417214",
|
| 27 |
+
api_secret = "jjOScVGochJYA7IxDam7L4HU2Ig", # Replace in production
|
| 28 |
secure=True
|
| 29 |
)
|
| 30 |
|
|
|
|
| 33 |
def greet_json():
|
| 34 |
return {"Hello": "World!"}
|
| 35 |
|
| 36 |
+
# β
MongoDB document count route for Images collection
|
| 37 |
@app.get("/count")
|
| 38 |
def count_docs():
|
| 39 |
+
collection = db["Images"]
|
|
|
|
| 40 |
count = collection.count_documents({})
|
| 41 |
return {"document_count": count}
|
| 42 |
|
| 43 |
+
# β
Upload image to Cloudinary and save URL to MongoDB
|
| 44 |
@app.post("/cloudinary/upload")
|
| 45 |
async def upload_sample(file: UploadFile = File(...)):
|
| 46 |
try:
|
| 47 |
# Upload the file to Cloudinary
|
| 48 |
result = cloudinary.uploader.upload(file.file, public_id=file.filename)
|
| 49 |
+
uploaded_url = result["secure_url"]
|
| 50 |
+
|
| 51 |
+
# Save image URL to MongoDB
|
| 52 |
+
collection = db["Images"]
|
| 53 |
+
doc = {"filename": file.filename, "url": uploaded_url}
|
| 54 |
+
collection.insert_one(doc)
|
| 55 |
+
|
| 56 |
+
return {"uploaded_url": uploaded_url}
|
| 57 |
except Exception as e:
|
| 58 |
return {"error": str(e)}
|
| 59 |
|