MuhammadInam456 commited on
Commit
0ab5549
·
verified ·
1 Parent(s): 2e47743
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. main.py +40 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ import cloudinary
4
+ import cloudinary.uploader
5
+ import os
6
+
7
+
8
+ # Cloudinary Configuration
9
+ cloudinary.config(
10
+ cloud_name='dys8zymcx',
11
+ api_key='754948374267897',
12
+ api_secret='rgvtpvNivIVWoBB7Od2_lE7VzLI'
13
+ )
14
+
15
+
16
+ # FastAPI App
17
+ app = FastAPI()
18
+
19
+ # CORS Middleware (Agar frontend se requests allow karna hai)
20
+ app.add_middleware(
21
+ CORSMiddleware,
22
+ allow_origins=["*"], # Saare origins allow karein (production mein specific origins use karein)
23
+ allow_methods=["*"],
24
+ allow_headers=["*"],
25
+ )
26
+
27
+ # Image Upload Endpoint
28
+ @app.post("/upload-image/")
29
+ async def upload_image(file: UploadFile = File(...)):
30
+ try:
31
+ # File ko Cloudinary par upload karein
32
+ result = cloudinary.uploader.upload(file.file, folder="user_images")
33
+ return {"message": "Image uploaded successfully!", "url": result["secure_url"]}
34
+ except Exception as e:
35
+ raise HTTPException(status_code=500, detail=str(e))
36
+
37
+ # Root Endpoint
38
+ @app.get("/")
39
+ def read_root():
40
+ return {"message": "FastAPI server is running!"}
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ fastapi
3
+ cloudinary
4
+ uvicorn==0.22.0
5
+