import gradio as gr import os import requests import binascii from PIL import Image url = "https://www.mindat.org/imagecache/46/9c/03220450016186848702713.jpg" headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3', "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9", "Cache-Control": "max-age=0", "Cookie": """mindat=n5e0bck7vvnn6e0o9tkb49fs75; cf_clearance=PMEAfGmJF_UGxZYgB2jsRx5KsiZyNf2plDbXs4HoN5I-1703800389-0-2-d8c97f25.71e5db39.8fc820c5-0.2.1703800389""", "Dnt": """1""", "If-Modified-Since": """Sat, 17 Apr 2021 18:41:12 GMT""", "If-None-Match": "607b2bc8-956c4", "Prefer": "safe", "Sec-Ch-Ua": r'"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"', "Sec-Ch-Ua-Mobile": "?0", "Sec-Ch-Ua-Platform": '"Windows"', "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1", "Upgrade-Insecure-Requests": "1",} def greet(): img = requests.get(url,headers = headers).content # print(img) print(len(img)) with open("./test.jpg","wb+") as f: f.write(img) return Image.open("./test.jpg") with gr.Blocks() as iface: btn = gr.Button("Run") img = gr.Image(type = "pil") btn.click(fn=greet,outputs = [img]) iface.launch()