Spaces:
Runtime error
Runtime error
File size: 1,403 Bytes
754a0f7 a3297fb bdb20a3 5fd7f4f bdb20a3 a3297fb 754a0f7 aa13c36 a3297fb 754a0f7 a3297fb 754a0f7 bdb20a3 754a0f7 5897420 754a0f7 5897420 |
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 |
import gradio as gr
from huggingface_hub import InferenceClient
import tempfile
import random
import math
from PIL import Image, ImageOps
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
client = InferenceClient(model="timbrooks/instruct-pix2pix")
# client = InferenceClient()
def model_call(prompt, input_image):
with tempfile.NamedTemporaryFile(suffix=".jpg", delete=True) as temp_file:
seed = random.randint(0, 100000)
text_cfg_scale = round(random.uniform(6.0, 9.0), ndigits=2)
image_cfg_scale = round(random.uniform(1.2, 1.8), ndigits=2)
width, height = input_image.size
factor = 512 / max(width, height)
factor = math.ceil(min(width, height) * factor / 64) * 64 / min(width, height)
width = int((width * factor) // 64) * 64
height = int((height * factor) // 64) * 64
image = ImageOps.fit(input_image, (width, height), method=Image.Resampling.LANCZOS)
image.save(temp_file.name)
print('test log here')
logger.info('logger test')
return client.image_to_image(temp_file.name, prompt=prompt)#, guidance_scale =7.5, num_inference_steps=50)
iface = gr.Interface(
fn=model_call,
inputs=[gr.inputs.Textbox(label="How to transform this image?"), gr.inputs.Image(type="pil")],
outputs=gr.outputs.Image(type="pil")
).launch(debug=True) |