Spaces:
Sleeping
Sleeping
BuildTools
commited on
Commit
·
d00d4d0
1
Parent(s):
e78267d
Add application file
Browse files- app.py +21 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pymongo import MongoClient
|
2 |
+
from fastapi import FastAPI
|
3 |
+
from bson import ObjectId # Pour gérer les ObjectId
|
4 |
+
|
5 |
+
# Connexion à MongoDB Atlas
|
6 |
+
uri = "mongodb+srv://lebaykserver:[email protected]/"
|
7 |
+
client = MongoClient(uri)
|
8 |
+
database = client["IA_SIGNATURE"]
|
9 |
+
collection = database["USER"]
|
10 |
+
|
11 |
+
# Initialisation de FastAPI
|
12 |
+
app = FastAPI()
|
13 |
+
|
14 |
+
@app.get("/user")
|
15 |
+
async def read_user():
|
16 |
+
user = collection.find_one()
|
17 |
+
|
18 |
+
if user:
|
19 |
+
user["_id"] = str(user["_id"]) # Convertir l'ObjectId en string
|
20 |
+
return user
|
21 |
+
return {"message": "Aucun utilisateur trouvé"}
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pymongo[srv]
|
2 |
+
fastapi
|
3 |
+
uvicorn[standard]
|