sezer91 commited on
Commit
1c3e5c8
·
verified ·
1 Parent(s): b86ab99

Delete request.py

Browse files
Files changed (1) hide show
  1. request.py +0 -38
request.py DELETED
@@ -1,38 +0,0 @@
1
- import requests
2
- from PIL import Image
3
- import base64
4
- from io import BytesIO
5
-
6
- url = "https://sezer91-sam.hf.space/segment/"
7
- file_path = "img.jpeg"
8
- file_path = "input.jpg"
9
-
10
- try:
11
- # Görüntü dosyasını kontrol et
12
- img = Image.open(file_path)
13
- if img.size[0] < 64 or img.size[1] < 64:
14
- raise ValueError(f"Görüntü boyutu çok küçük: {img.size[0]}x{img.size[1]}. Minimum 64x64 piksel olmalı.")
15
- print(f"Görüntü boyutu: {img.size[0]}x{img.size[1]}")
16
-
17
- with open(file_path, "rb") as file:
18
- files = {"file": file}
19
- response = requests.post(url, files=files)
20
-
21
- if response.status_code == 200:
22
- result = response.json()
23
- print("Başarılı! Maske alındı.")
24
- # Base64'ü PNG olarak kaydet
25
- base64_string = result["mask"].split(",")[1] # "data:image/png;base64," kısmını atla
26
- img_data = base64.b64decode(base64_string)
27
- img = Image.open(BytesIO(img_data))
28
- img.save("output_mask.png")
29
- print("Maske 'output_mask.png' olarak kaydedildi.")
30
- else:
31
- print(f"Hata: {response.status_code}, {response.text}")
32
-
33
- except FileNotFoundError:
34
- print(f"Hata: {file_path} dosyası bulunamadı.")
35
- except ValueError as ve:
36
- print(f"Hata: {str(ve)}")
37
- except Exception as e:
38
- print(f"Hata: {str(e)}")