-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostfile.py
More file actions
59 lines (45 loc) · 1.66 KB
/
Copy pathpostfile.py
File metadata and controls
59 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# import requests
# def send_image(url, image_path):
# try:
# # Membuka file gambar
# with open(image_path, 'rb') as file:
# # Membuat permintaan POST
# response = requests.post(url, files={'image': file})
# # Menampilkan respons dari server
# print(response.json())
# except Exception as e:
# print(str(e))
# # URL endpoint untuk mengirim gambar
# url = 'https://vlm2jkrd-5000.asse.devtunnels.ms/predict' # Ganti dengan URL API Anda
# # Path gambar yang akan dikirim
# image_path = '12.png' # Ganti dengan path gambar yang sesuai
# # Mengirim gambar ke server
# send_image(url, image_path)
import requests
from PIL import Image
def send_image(url, image_path):
try:
# Mengonversi gambar ke mode RGB
convert_to_rgb(image_path)
# Membuka file gambar
with open(image_path, 'rb') as file:
# Membuat permintaan POST
response = requests.post(url, files={'image': file})
# Menampilkan respons dari server
print(response.json())
except Exception as e:
print(str(e))
# Fungsi untuk mengonversi gambar ke mode RGB
def convert_to_rgb(image_path):
try:
with Image.open(image_path) as img:
img = img.convert("RGB")
img.save(image_path)
except Exception as e:
print(str(e))
# URL endpoint untuk mengirim gambar
url = 'https://vlm2jkrd-5000.asse.devtunnels.ms/predict' # Ganti dengan URL API Anda
# Path gambar yang akan dikirim
image_path = '12.png' # Ganti dengan path gambar yang sesuai
# Mengirim gambar ke server
send_image(url, image_path)