sam / request.py
sezer91's picture
sd
aead903
raw
history blame
945 Bytes
import requests
url = "https://sezer91-sam.hf.space/segment/"
file_path = "img.jpeg"
try:
with open(file_path, "rb") as file:
files = {"file": file}
response = requests.post(url, files=files)
if response.status_code == 200:
result = response.json()
print("Başarılı! Maske alındı.")
# Base64'ü PNG olarak kaydet
import base64
from io import BytesIO
from PIL import Image
base64_string = result["mask"].split(",")[1] # "data:image/png;base64," kısmını atla
img_data = base64.b64decode(base64_string)
img = Image.open(BytesIO(img_data))
img.save("output_mask.png")
print("Maske 'output_mask.png' olarak kaydedildi.")
else:
print(f"Hata: {response.status_code}, {response.text}")
except FileNotFoundError:
print(f"Hata: {file_path} dosyası bulunamadı.")
except Exception as e:
print(f"Hata: {str(e)}")