Deadmon commited on
Commit
4b86c44
·
verified ·
1 Parent(s): fa6b35c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -81
app.py CHANGED
@@ -1,19 +1,11 @@
1
- # App code based on: https://github.com/petergro-hub/ComicInpainting
2
- # Model based on: https://github.com/saic-mdal/lama
3
-
4
  import numpy as np
5
- import pandas as pd
6
  import streamlit as st
7
- import os
8
- from datetime import datetime
9
  from PIL import Image
10
  from streamlit_drawable_canvas import st_canvas
11
  from io import BytesIO
12
  from copy import deepcopy
13
-
14
  from src.core import process_inpaint
15
 
16
-
17
  def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
18
  if fmt not in ["jpg", "png"]:
19
  raise Exception(f"Unknown image format (Available: {fmt} - case sensitive)")
@@ -32,8 +24,6 @@ def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
32
  mime=mime,
33
  )
34
 
35
-
36
-
37
  if "button_id" not in st.session_state:
38
  st.session_state["button_id"] = ""
39
  if "color_to_label" not in st.session_state:
@@ -41,6 +31,7 @@ if "color_to_label" not in st.session_state:
41
 
42
  if 'reuse_image' not in st.session_state:
43
  st.session_state.reuse_image = None
 
44
  def set_image(img):
45
  st.session_state.reuse_image = img
46
 
@@ -113,17 +104,14 @@ if uploaded_file is not None:
113
  im[background]=[0,0,0,255]
114
  im[drawing]=[0,0,0,0] # RGBA
115
 
116
- reuse = False
117
-
118
  if st.button('Submit'):
119
 
120
  with st.spinner("AI is doing the magic!"):
121
- output = process_inpaint(np.array(img_input), np.array(im)) #TODO Put button here
122
  img_output = Image.fromarray(output).convert("RGB")
123
 
124
  st.write("AI has finished the job!")
125
  st.image(img_output)
126
- # reuse = st.button('Edit again (Re-use this image)', on_click=set_image, args=(inpainted_img, ))
127
 
128
  uploaded_name = os.path.splitext(uploaded_file.name)[0]
129
  image_download_button(
@@ -136,87 +124,41 @@ if uploaded_file is not None:
136
  st.info("**TIP**: If the result is not perfect, you can download it then "
137
  "upload then remove the artifacts.")
138
 
139
-
 
140
  <style>
141
  body {
142
  font-family: 'Arial', sans-serif;
143
- margin: 0;
144
  background-color: #1a1a2e;
145
  color: #ffffff;
146
- overflow-x: hidden;
147
- }
148
-
149
- .stButton button {
150
- background-color: #ffffff;
151
- color: #1a1a2e;
152
- }
153
-
154
- .stButton button:hover {
155
- background-color: #9370db;
156
- color: #ffffff;
157
- }
158
-
159
- .stSlider {
160
- color: #ffffff;
161
- }
162
-
163
- .stSlider .stSlider-label {
164
- color: #ffffff;
165
- }
166
-
167
- .stSlider .stSlider-track {
168
- background-color: #4a4a5e;
169
- }
170
-
171
- .stSlider .stSlider-thumb {
172
- background-color: #ffffff;
173
  }
174
-
175
- .stMarkdown {
176
- color: #ffffff;
177
- }
178
-
179
- .stSpinner {
180
- color: #ffffff;
181
- }
182
-
183
- .stFileUploader {
184
  background-color: #2a2a3e;
185
- color: #ffffff;
186
- border-color: #4a4a5e;
187
- }
188
-
189
- .stFileUploader:hover {
190
- background-color: #3a3a4e;
191
  }
192
-
193
- .stImage {
 
194
  max-width: 100%;
195
  height: auto;
196
  }
197
-
198
- .stTextInput input {
199
- background-color: #2a2a3e;
200
- color: #ffffff;
201
- border-color: #4a4a5e;
202
- }
203
-
204
- .stTextInput input:focus {
205
- border-color: #6a6a7e;
206
- }
207
-
208
- .stDownloadButton {
209
- background-color: #ffffff;
210
- color: #1a1a2e;
211
- }
212
-
213
- .stDownloadButton:hover {
214
  background-color: #9370db;
 
 
 
215
  color: #ffffff;
 
 
216
  }
217
-
218
- .stInfo {
219
- background-color: #2a2a3e;
 
220
  color: #ffffff;
221
  }
222
  </style>
 
 
 
 
 
1
  import numpy as np
 
2
  import streamlit as st
 
 
3
  from PIL import Image
4
  from streamlit_drawable_canvas import st_canvas
5
  from io import BytesIO
6
  from copy import deepcopy
 
7
  from src.core import process_inpaint
8
 
 
9
  def image_download_button(pil_image, filename: str, fmt: str, label="Download"):
10
  if fmt not in ["jpg", "png"]:
11
  raise Exception(f"Unknown image format (Available: {fmt} - case sensitive)")
 
24
  mime=mime,
25
  )
26
 
 
 
27
  if "button_id" not in st.session_state:
28
  st.session_state["button_id"] = ""
29
  if "color_to_label" not in st.session_state:
 
31
 
32
  if 'reuse_image' not in st.session_state:
33
  st.session_state.reuse_image = None
34
+
35
  def set_image(img):
36
  st.session_state.reuse_image = img
37
 
 
104
  im[background]=[0,0,0,255]
105
  im[drawing]=[0,0,0,0] # RGBA
106
 
 
 
107
  if st.button('Submit'):
108
 
109
  with st.spinner("AI is doing the magic!"):
110
+ output = process_inpaint(np.array(img_input), np.array(im))
111
  img_output = Image.fromarray(output).convert("RGB")
112
 
113
  st.write("AI has finished the job!")
114
  st.image(img_output)
 
115
 
116
  uploaded_name = os.path.splitext(uploaded_file.name)[0]
117
  image_download_button(
 
124
  st.info("**TIP**: If the result is not perfect, you can download it then "
125
  "upload then remove the artifacts.")
126
 
127
+ # CSS styles for dark mode and responsiveness
128
+ st.markdown("""
129
  <style>
130
  body {
131
  font-family: 'Arial', sans-serif;
 
132
  background-color: #1a1a2e;
133
  color: #ffffff;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  }
135
+ .stApp {
136
+ max-width: 800px;
137
+ margin: 0 auto;
138
+ padding: 20px;
 
 
 
 
 
 
139
  background-color: #2a2a3e;
140
+ border-radius: 10px;
 
 
 
 
 
141
  }
142
+ canvas {
143
+ display: block;
144
+ margin: 0 auto;
145
  max-width: 100%;
146
  height: auto;
147
  }
148
+ .stButton button {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  background-color: #9370db;
150
+ border: none;
151
+ padding: 10px;
152
+ border-radius: 5px;
153
  color: #ffffff;
154
+ font-weight: bold;
155
+ cursor: pointer;
156
  }
157
+ .stButton button:hover {
158
+ background-color: #7b5fbf;
159
+ }
160
+ .stSlider {
161
  color: #ffffff;
162
  }
163
  </style>
164
+ """, unsafe_allow_html=True)