kael558 commited on
Commit
36309df
1 Parent(s): 016107d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -36
app.py CHANGED
@@ -14,6 +14,7 @@ from matplotlib import pyplot as plt
14
  from torchvision import transforms
15
  from diffusers import DiffusionPipeline
16
 
 
17
  auth_token = os.environ.get("API_TOKEN") or True
18
 
19
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -33,47 +34,30 @@ def predict(dict, prompt=""):
33
  output = pipe(prompt = prompt, image=init_image, mask_image=mask,guidance_scale=7.5)
34
  return output.images[0], gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
35
 
 
36
 
37
-
38
-
39
-
 
 
 
 
 
 
 
40
 
41
 
42
  image_blocks = gr.Blocks()
43
  with image_blocks as demo:
44
- with gr.Group():
45
- with gr.Box():
46
- with gr.Row():
47
- with gr.Column():
48
- image = gr.Image(source='upload', tool='sketch', elem_id="image_upload", type="pil",
49
- label="Upload").style(height=400)
50
- with gr.Row(elem_id="prompt-container").style(mobile_collapse=False, equal_height=True):
51
- prompt = gr.Textbox(placeholder='Your prompt (what you want in place of what is erased)',
52
- show_label=False, elem_id="input-text")
53
- btn = gr.Button("Inpaint!").style(
54
- margin=False,
55
- rounded=(False, True, True, False),
56
- full_width=False,
57
- )
58
- with gr.Column():
59
- image_out = gr.Image(label="Output", elem_id="output-img").style(height=400)
60
-
61
- btn.click(fn=predict, inputs=[image, prompt],
62
- outputs=[image_out])
63
 
64
- gr.HTML(
65
- """
66
- <div class="footer">
67
- <p>Model by <a href="https://huggingface.co/runwayml" style="text-decoration: underline;" target="_blank">RunwayML</a> - Gradio Demo by 🤗 Hugging Face
68
- </p>
69
- </div>
70
- <div class="acknowledgments">
71
- <p><h4>LICENSE</h4>
72
- The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
73
- <p><h4>Biases and content acknowledgment</h4>
74
- Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
75
- </div>
76
- """
77
- )
78
 
79
  image_blocks.launch()
 
14
  from torchvision import transforms
15
  from diffusers import DiffusionPipeline
16
 
17
+ """
18
  auth_token = os.environ.get("API_TOKEN") or True
19
 
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
34
  output = pipe(prompt = prompt, image=init_image, mask_image=mask,guidance_scale=7.5)
35
  return output.images[0], gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
36
 
37
+ """
38
 
39
+ def add_text(text, image, image_process_mode, request: gr.Request):
40
+ text = text[:1536] # Hard cut-off
41
+ if image is not None:
42
+ print(image)
43
+ text = text[:1200] # Hard cut-off for images
44
+ if "<image>" not in text:
45
+ # text = '<Image><image></Image>' + text
46
+ text = text + "\n<image>"
47
+ text = (text, image, image_process_mode)
48
+ print(text)
49
 
50
 
51
  image_blocks = gr.Blocks()
52
  with image_blocks as demo:
53
+ imagebox = gr.Image(type="pil")
54
+ submit_btn = gr.Button(value="Send", variant="primary", interactive=False)
55
+ submit_btn.click(
56
+ add_text,
57
+ [textbox, imagebox, image_process_mode],
58
+ [],
59
+ )
60
+
 
 
 
 
 
 
 
 
 
 
 
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  image_blocks.launch()