K00B404 commited on
Commit
b8c83ab
·
verified ·
1 Parent(s): 69a1506

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -40
app.py CHANGED
@@ -1,44 +1,23 @@
1
- import gradio as gr
2
 
3
- # Define the main chat response function.
4
- def chat_response(user_input):
5
- # Your chat response logic here.
6
- return "Hello, I am a chatbot. How can I help you?"
7
 
8
- # Create the Gradio interface.
9
- iface = gr.Interface(
10
- fn=chat_response,
11
- inputs=gr.Textbox(label="User Input"),
12
- outputs=gr.Textbox(label="Chatbot Response"),
13
- )
14
 
15
- # Add the code editor and debug screen.
16
- code_editor = gr.Code(label="Code Editor")
17
- debug_screen = gr.Textbox(label="Debug Screen")
 
 
 
 
18
 
19
- # Define the function to execute the Python code.
20
- def execute_code(code):
21
- try:
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]