Spaces:
Runtime error
Runtime error
| 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) |