File size: 966 Bytes
74ea73e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
# file: api.py.py
# time: 20:37 2022/12/6 
# author: yangheng <hy345@exeter.ac.uk>
# github: https://github.com/yangheng95
# huggingface: https://huggingface.co/yangheng
# google scholar: https://scholar.google.com/citations?user=NPq5a_0AAAAJ&hl=en
# Copyright (C) 2021. All Rights Reserved.
import base64
import requests
from PIL import Image
from io import BytesIO

import requests

url = "https://images.pexels.com/photos/666839/pexels-photo-666839.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2"

response = requests.get(url)
image = Image.open(BytesIO(response.content))
# convert image to base64 string
image = base64.b64encode(image.tobytes()).decode('utf-8')

response = requests.post("http://127.0.0.1:7860/run/magnify_image", json={
    "data": [
        "data:image/png;base64,{}".format(image),
        2,
    ]}).json()

data = response["data"]

img = Image.open(BytesIO(response.content))
img.show()
img.save('test_api.png')