Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,23 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
outputs=gr.Textbox(label="Chatbot Response"),
|
| 13 |
-
)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Execute the code and capture the output.
|
| 23 |
-
output = eval(code)
|
| 24 |
-
debug_screen.update(f"Code executed successfully.\nOutput: {output}")
|
| 25 |
-
except Exception as e:
|
| 26 |
-
debug_screen.update(f"Error executing code: {e}")
|
| 27 |
-
|
| 28 |
-
# Create the Gradio interface for the code execution.
|
| 29 |
-
code_execution_iface = gr.Interface(
|
| 30 |
-
fn=execute_code,
|
| 31 |
-
inputs=code_editor,
|
| 32 |
-
outputs=debug_screen,
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
# Add the screens to the main interface.
|
| 36 |
-
iface.cache_examples(
|
| 37 |
-
[
|
| 38 |
-
("What is the capital of France?", "Paris"),
|
| 39 |
-
("What is the square root of 16?", 4),
|
| 40 |
-
]
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
# Launch the Gradio interface.
|
| 44 |
-
iface.launch()
|
|
|
|
| 1 |
+
pip install diffusers accelerate safetensors transformers
|
| 2 |
|
| 3 |
+
import PIL
|
| 4 |
+
import requests
|
| 5 |
+
import torch
|
| 6 |
+
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
|
| 7 |
|
| 8 |
+
model_id = "timbrooks/instruct-pix2pix"
|
| 9 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
|
| 10 |
+
pipe.to("cuda")
|
| 11 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
url = "https://raw.githubusercontent.com/timothybrooks/instruct-pix2pix/main/imgs/example.jpg"
|
| 14 |
+
def download_image(url):
|
| 15 |
+
image = PIL.Image.open(requests.get(url, stream=True).raw)
|
| 16 |
+
image = PIL.ImageOps.exif_transpose(image)
|
| 17 |
+
image = image.convert("RGB")
|
| 18 |
+
return image
|
| 19 |
+
image = download_image(url)
|
| 20 |
|
| 21 |
+
prompt = "turn him into cyborg"
|
| 22 |
+
images = pipe(prompt, image=image, num_inference_steps=10, image_guidance_scale=1).images
|
| 23 |
+
images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|