File size: 774 Bytes
42af165
 
 
 
cd3429d
 
d108f45
cd3429d
42af165
cd3429d
 
 
 
140bf00
42af165
02a17c2
cd3429d
02a17c2
42af165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import requests
import gradio as gr
from PIL import Image
# from dotenv import load_dotenv
import os
import io
token = os.environ['HF_TOKEN']



# load_dotenv()
# token = os.environ.get("HF_TOKEN", "")
print(token)
API_URL = "https://api-inference.huggingface.co/models/playgroundai/playground-v2-1024px-aesthetic"
bearer_token = "Bearer " + str(token)
# token = 
headers = {"Authorization": bearer_token}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    image_bytes = response.content
    # image = Image.open(io.BytesIO(image_bytes))
    # return image_bytes
    image = Image.open(io.BytesIO(image_bytes))
    return image



with gr.Blocks() as demo:
    gr.Interface(fn=query, inputs="text", outputs="image")

demo.launch()