Seniordev22 commited on
Commit
e93d48e
Β·
verified Β·
1 Parent(s): ec2865e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -3,33 +3,41 @@ from fastapi.responses import StreamingResponse
3
  import io
4
  from bald_processor import make_realistic_bald
5
 
6
- app = FastAPI(title="Make Me Bald API 😎")
 
 
7
 
8
  @app.post("/make-bald/")
9
  async def bald_endpoint(file: UploadFile = File(...)):
10
  if not file.content_type.startswith("image/"):
11
- raise HTTPException(400, detail="Sirf image file upload kar bhai!")
12
 
13
  try:
14
  contents = await file.read()
15
  bald_bytes = make_realistic_bald(contents)
16
 
 
 
 
 
 
 
17
  except ValueError as ve:
18
  error_detail = str(ve)
19
  if error_detail == "NO_HAIR_DETECTED":
20
  raise HTTPException(status_code=400, detail="NO_HAIR")
21
  else:
22
  raise HTTPException(status_code=400, detail=error_detail)
23
-
24
- except Exception as e:
25
- raise HTTPException(500, detail=f"Processing mein error: {str(e)}")
26
 
27
- return StreamingResponse(
28
- io.BytesIO(bald_bytes),
29
- media_type="image/jpeg",
30
- headers={"Content-Disposition": "attachment; filename=bald_version.jpg"}
31
- )
32
 
33
  @app.get("/")
34
  def home():
35
- return {"message": "Bald banne aaya? POST /make-bald/ pe image daal!"}
 
 
 
 
 
3
  import io
4
  from bald_processor import make_realistic_bald
5
 
6
+ app = FastAPI(title="Make Me Bald API 😎",
7
+ description="Upload photo β†’ Get realistic bald version! πŸ§‘β€πŸ¦²",
8
+ version="1.0")
9
 
10
  @app.post("/make-bald/")
11
  async def bald_endpoint(file: UploadFile = File(...)):
12
  if not file.content_type.startswith("image/"):
13
+ raise HTTPException(status_code=400, detail="Sirf image file upload kar bhai! (jpeg/png etc.)")
14
 
15
  try:
16
  contents = await file.read()
17
  bald_bytes = make_realistic_bald(contents)
18
 
19
+ return StreamingResponse(
20
+ io.BytesIO(bald_bytes),
21
+ media_type="image/jpeg",
22
+ headers={"Content-Disposition": "attachment; filename=bald_version.jpg"}
23
+ )
24
+
25
  except ValueError as ve:
26
  error_detail = str(ve)
27
  if error_detail == "NO_HAIR_DETECTED":
28
  raise HTTPException(status_code=400, detail="NO_HAIR")
29
  else:
30
  raise HTTPException(status_code=400, detail=error_detail)
 
 
 
31
 
32
+ except Exception as e:
33
+ # Optional: print for logs
34
+ print(f"Processing error: {str(e)}")
35
+ raise HTTPException(status_code=500, detail=f"Processing mein error: {str(e)}")
 
36
 
37
  @app.get("/")
38
  def home():
39
+ return {
40
+ "message": "Bald banne aaya? 😏",
41
+ "how_to_use": "POST request bhejo /make-bald/ pe with form-data key 'file' aur image attach karo.",
42
+ "example": "cURL: curl -X POST -F 'file=@your_photo.jpg' https://your-space-url.hf.space/make-bald/"
43
+ }