Spaces:
Runtime error
Runtime error
File size: 877 Bytes
93a61c7 0a66490 93a61c7 0a66490 93a61c7 0a66490 93a61c7 |
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 |
import requests
import base64
import io
from PIL import Image
import gradio as gr
API_TOKEN = os.environ["API_TOKEN"] # replace with your own API Token here
API_URL = "https://api-inference.huggingface.co/models/Kvikontent/kviimager2.0"
HEADERS = {
'Content-Type': 'application/json',
'Authorization': f'{API_TOKEN}'
}
def predictor(prompt):
payload = {'inputs': prompt}
try:
response = requests.request("POST", url=API_URL, data=payload, headers=HEADERS)
if not (response is None or response.status_code != 200):
result = response.text[7:-5]
return Image.open(io.BytesIO(base64.b64decode(result)))
except Exception as e:
print('Error processing request')
raise ValueError(e)
iface = gr.Interface(fn=predictor, inputs="textbox", outputs='image').launch() |