warhawkmonk commited on
Commit
4947b21
·
verified ·
1 Parent(s): c3d905a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +442 -442
app.py CHANGED
@@ -1,442 +1,442 @@
1
- import pandas as pd
2
- from PIL import Image
3
- import streamlit as st
4
- import cv2
5
- from streamlit_drawable_canvas import st_canvas
6
- import torch
7
- from diffusers import AutoPipelineForInpainting
8
- import numpy as np
9
- from streamlit_image_select import image_select
10
- import os
11
- import requests
12
- from streamlit_navigation_bar import st_navbar
13
- from langchain_community.llms import Ollama
14
- import base64
15
- from io import BytesIO
16
- from PIL import Image, ImageDraw
17
- from streamlit_lottie import st_lottie
18
- from streamlit_option_menu import option_menu
19
- import json
20
- from transformers import pipeline
21
- import streamlit as st
22
- from streamlit_modal import Modal
23
- import streamlit.components.v1 as components
24
- from datetime import datetime
25
-
26
-
27
- def image_to_base64(image_path):
28
- with open(image_path, "rb") as img_file:
29
- return base64.b64encode(img_file.read()).decode()
30
-
31
-
32
- @st.cache_resource
33
- def load_model():
34
- pipeline_ = AutoPipelineForInpainting.from_pretrained("kandinsky-community/kandinsky-2-2-decoder-inpaint", torch_dtype=torch.float16).to("cuda")
35
- return pipeline_
36
-
37
- # @st.cache_resource
38
- def prompt_improvment(pre_prompt):
39
-
40
- llm = Ollama(model="llama3:latest",num_ctx=1000)
41
- enhancement="Please use details from the prompt mentioned above, focusing only what user is thinking with the prompt and also add 8k resolution. Its a request only provide image description and brief prompt no other text."
42
- prompt = pre_prompt+"\n"+enhancement
43
- # result = llm.invoke(prompt)
44
- return llm.stream(prompt)
45
- def numpy_to_list(array):
46
-
47
- current=[]
48
- for value in array:
49
- if isinstance(value,type(np.array([]))):
50
- result=numpy_to_list(value)
51
- current.append(result)
52
- else:
53
-
54
- current.append(int(value))
55
- return current
56
-
57
-
58
-
59
- @st.cache_resource
60
- def llm_text_response():
61
- llm = Ollama(model="llama3:latest",num_ctx=1000)
62
- return llm.stream
63
-
64
- def model_single_out(prompt):
65
- pipe=load_model()
66
- image = pipe(prompt).images[0]
67
- return image
68
-
69
- def model_out_put(init_image,mask_image,prompt,negative_prompt):
70
- pipeline_ = load_model()
71
- image = pipeline_(prompt=prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask_image).images[0]
72
- return image
73
-
74
- @st.cache_resource
75
- def multimodel():
76
- pipeline_ = pipeline("text-classification", model = "model_collection\model_4")
77
- return pipeline_
78
-
79
- def multimodel_output(prompt):
80
- pipeline_ = multimodel()
81
- image = pipeline_(prompt)
82
- return image[0]['label']
83
-
84
- def d4_to_3d(image):
85
- formatted_array=[]
86
- for j in image:
87
- neste_list=[]
88
- for k in j:
89
- if any([True if i>0 else False for i in k]):
90
- neste_list.append(True)
91
- else:
92
- neste_list.append(False)
93
- formatted_array.append(neste_list)
94
- print(np.shape(formatted_array))
95
- return np.array(formatted_array)
96
-
97
- st.set_page_config(layout="wide")
98
-
99
- st.write(str(os.getcwd()))
100
-
101
- img_selection=None
102
- # Specify canvas parameters in application
103
- drawing_mode = st.sidebar.selectbox(
104
- "Drawing tool:", ("freedraw","point", "line", "rect", "circle", "transform")
105
- )
106
-
107
-
108
- dictionary=st.session_state
109
- if "every_prompt_with_val" not in dictionary:
110
- dictionary['every_prompt_with_val']=[]
111
- if "current_image" not in dictionary:
112
- dictionary['current_image']=[]
113
- if "prompt_collection" not in dictionary:
114
- dictionary['prompt_collection']=[]
115
- if "user" not in dictionary:
116
- dictionary['user']=None
117
- if "current_session" not in dictionary:
118
- dictionary['current_session']=None
119
-
120
- stroke_width = st.sidebar.slider("Stroke width: ", 1, 25, 20)
121
- if drawing_mode == 'point':
122
- point_display_radius = st.sidebar.slider("Point display radius: ", 1, 25, 3)
123
- stroke_color = '#000000'
124
- bg_color = "#eee"
125
-
126
-
127
- column1,column2=st.columns([0.7,0.35])
128
-
129
- with open("DataBase\datetimeRecords.json","r") as read:
130
- dateTimeRecord=json.load(read)
131
- with column2:
132
- st.header("HISTORY")
133
- tab1,tab2,tab3,tab4=st.tabs(["CHAT HISTORY","IMAGES","PROMPT IMPROVEMENT","LOGIN"])
134
- with tab1:
135
-
136
-
137
-
138
- if not len(dictionary['every_prompt_with_val']):
139
- st.header("I will store all the chat for the current session")
140
- with open("lotte_animation_saver\\animation_4.json") as read:
141
- url_json=json.load(read)
142
- st_lottie(url_json,height = 400)
143
- else:
144
-
145
- with st.container(height=600):
146
-
147
-
148
- for index,prompts_ in enumerate(dictionary['every_prompt_with_val'][::-1]):
149
- if prompts_[-1]=="@working":
150
- if index==0:
151
- st.write(prompts_[0].upper())
152
- data_need=st.write_stream(llm_text_response()(prompts_[0]))
153
- dictionary['every_prompt_with_val'][-1]=(prompts_[0],str(data_need))
154
-
155
- elif isinstance(prompts_[-1],str):
156
- if index==0:
157
- st.text_area(label=prompts_[0].upper(),value=prompts_[-1],height=500)
158
- else:
159
- st.text_area(label=prompts_[0].upper(),value=prompts_[-1])
160
-
161
- else:
162
- st.write(prompts_[0].upper())
163
- with st.container(height=400):
164
- format1,format2=st.columns([0.2,0.8])
165
- with format1:
166
- new_img=Image.open("ALL_image_formation\image_gen.png")
167
- st.write("<br>",unsafe_allow_html=True)
168
- size = min(new_img.size)
169
- mask = Image.new('L', (size, size), 0)
170
- draw = ImageDraw.Draw(mask)
171
- draw.ellipse((0, 0, size, size), fill=255)
172
-
173
- image = new_img.crop((0, 0, size, size))
174
- image.putalpha(mask)
175
- st.image(image)
176
- with format2:
177
-
178
- st.write("<br>",unsafe_allow_html=True)
179
- size = min(prompts_[-1].size)
180
- mask = Image.new('L', (size, size), 0)
181
- draw = ImageDraw.Draw(mask)
182
- draw.ellipse((0, 0, size, size), fill=255)
183
-
184
- # Crop the image to a square and apply the mask
185
- image = prompts_[-1].crop((0, 0, size, size))
186
- image.putalpha(mask)
187
- st.image(image)
188
-
189
- with tab2:
190
-
191
- if "current_image" in dictionary and len(dictionary['current_image']):
192
- with st.container(height=600):
193
- dictinory_length=len(dictionary['current_image'])
194
-
195
- img_selection = image_select(
196
- label="",
197
- images=dictionary['current_image'] if len(dictionary['current_image'])!=0 else None,
198
- )
199
- if img_selection in dictionary['current_image']:
200
- dictionary['current_image'].remove(img_selection)
201
- dictionary['current_image'].insert(0,img_selection)
202
- # st.rerun()
203
-
204
- img_selection.save("image.png")
205
- with open("image.png", "rb") as file:
206
- downl=st.download_button(label="DOWNLOAD",data=file,file_name="image.png",mime="image/png")
207
- os.remove("image.png")
208
- else:
209
-
210
- st.header("This section will store the updated images")
211
- with open("lotte_animation_saver\\animation_1.json") as read:
212
- url_json=json.load(read)
213
- st_lottie(url_json,height = 400)
214
- with tab3:
215
- if len(dictionary['prompt_collection'])!=0:
216
- with st.container(height=600):
217
- prompt_selection=st.selectbox(label="Select the prompt for improvment",options=["Mention below are prompt history"]+dictionary["prompt_collection"],index=0)
218
-
219
- if prompt_selection!="Mention below are prompt history":
220
-
221
- generated_prompt=prompt_improvment(prompt_selection)
222
- dictionary['generated_image_prompt'].append(generated_prompt)
223
- st.write_stream(generated_prompt)
224
-
225
- else:
226
-
227
- st.header("This section will provide prompt improvement section")
228
- with open("lotte_animation_saver\\animation_3.json") as read:
229
- url_json=json.load(read)
230
- st_lottie(url_json,height = 400)
231
- with tab4:
232
-
233
- # with st.container(height=600):
234
-
235
- if not dictionary['user'] :
236
- with st.form("my_form"):
237
- # st.header("Please login for save your data")
238
- with open("lotte_animation_saver\\animation_5.json") as read:
239
- url_json=json.load(read)
240
- st_lottie(url_json,height = 200)
241
- user_id = st.text_input("user login")
242
- password = st.text_input("password",type="password")
243
- submitted_login = st.form_submit_button("Submit")
244
- # Every form must have a submit button.
245
-
246
- if submitted_login:
247
- with open("DataBase\login.json","r") as read:
248
- login_base=json.load(read)
249
- if user_id in login_base and login_base[user_id]==password:
250
- dictionary['user']=user_id
251
- st.rerun()
252
- else:
253
- st.error("userid or password incorrect")
254
-
255
- st.write("working")
256
- modal = Modal(
257
- "Sign up",
258
- key="demo-modal",
259
-
260
- padding=10, # default value
261
- max_width=600 # default value
262
- )
263
- open_modal = st.button("sign up")
264
- if open_modal:
265
- modal.open()
266
-
267
- if modal.is_open():
268
- with modal.container():
269
-
270
- with st.form("my_form1"):
271
- sign_up_column_left,sign_up_column_right=st.columns(2)
272
- with sign_up_column_left:
273
- with open("lotte_animation_saver\\animation_6.json") as read:
274
- url_json=json.load(read)
275
- st_lottie(url_json,height = 200)
276
-
277
- with sign_up_column_right:
278
- user_id = st.text_input("user login")
279
- password = st.text_input("password",type="password")
280
- submitted_signup = st.form_submit_button("Submit")
281
-
282
- if submitted_signup:
283
- with open("DataBase\login.json","r") as read:
284
- login_base=json.load(read)
285
- if not login_base:
286
- login_base={}
287
- if user_id not in login_base:
288
- login_base[user_id]=password
289
- with open("DataBase\login.json","w") as write:
290
- json.dump(login_base,write,indent=2)
291
- st.success("you are a part now")
292
- dictionary['user']=user_id
293
- modal.close()
294
- else:
295
- st.error("user id already exists")
296
- else:
297
- st.header("REPORTED ISSUES")
298
- with st.container(height=370):
299
-
300
- with open("DataBase\datetimeRecords.json") as feedback:
301
- temp_issue=json.load(feedback)
302
-
303
- arranged_feedback=reversed(temp_issue['database'])
304
-
305
- for report in arranged_feedback:
306
- user_columns,user_feedback=st.columns([0.3,0.8])
307
-
308
- with user_columns:
309
- st.write(report[-1])
310
- with user_feedback:
311
- st.write(report[1])
312
-
313
- feedback=st.text_area("Feedback Report and Improvement",placeholder="")
314
- summit=st.button("submit")
315
- if summit:
316
- with open("DataBase\datetimeRecords.json","r") as feedback_sumit:
317
- temp_issue_submit=json.load(feedback_sumit)
318
- if "database" not in temp_issue_submit:
319
- temp_issue_submit["database"]=[]
320
- temp_issue_submit["database"].append((str(datetime.now()),feedback,dictionary['user']))
321
- with open("DataBase\datetimeRecords.json","w") as feedback_sumit:
322
- json.dump(temp_issue_submit,feedback_sumit)
323
-
324
-
325
-
326
- # st.rerun()
327
-
328
-
329
-
330
-
331
-
332
-
333
- bg_image = st.sidebar.file_uploader("PLEASE UPLOAD IMAGE FOR EDITING:", type=["png", "jpg"])
334
- bg_doc = st.sidebar.file_uploader("PLEASE UPLOAD DOC FOR PPT/PDF/STORY:", type=["pdf","xlsx"])
335
-
336
-
337
- if "bg_image" not in dictionary:
338
- dictionary["bg_image"]=None
339
-
340
- if img_selection and dictionary['bg_image']==bg_image:
341
- gen_image=dictionary['current_image'][0]
342
- else:
343
- if bg_image:
344
- gen_image=Image.open(bg_image)
345
- else:
346
- gen_image=None
347
-
348
-
349
-
350
-
351
-
352
-
353
- with column1:
354
- # Create a canvas component
355
- changes,implementation,current=st.columns([0.3,0.6,0.3])
356
-
357
- with implementation:
358
- st.write("<br>"*5,unsafe_allow_html=True)
359
- canvas_result = st_canvas(
360
- fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
361
- stroke_width=stroke_width,
362
- stroke_color=stroke_color,
363
- background_color=bg_color,
364
- background_image=gen_image if gen_image else Image.open("ALL_image_formation\image_gen.png"),
365
- update_streamlit=True,
366
- height=500,
367
- width=500,
368
- drawing_mode=drawing_mode,
369
- point_display_radius=point_display_radius if drawing_mode == 'point' else 0,
370
- key="canvas",
371
- )
372
-
373
-
374
-
375
-
376
-
377
- with column1:
378
- # prompt=st.text_area("Please provide the prompt")
379
- prompt=st.chat_input("Please provide the prompt")
380
-
381
- negative_prompt="the black masked area"
382
-
383
- # run=st.button("run_experiment")
384
-
385
-
386
-
387
- if canvas_result.image_data is not None:
388
- if prompt:
389
-
390
- text_or_image=multimodel_output(prompt)
391
-
392
- if text_or_image=="LABEL_0":
393
-
394
- if "generated_image_prompt" not in dictionary:
395
- dictionary['generated_image_prompt']=[]
396
- if prompt not in dictionary['prompt_collection'] and prompt not in dictionary['generated_image_prompt']:
397
- dictionary['prompt_collection']=[prompt]+dictionary['prompt_collection']
398
- new_size=np.array(canvas_result.image_data).shape[:2]
399
- new_size=(new_size[-1],new_size[0])
400
- if bg_image!=dictionary["bg_image"] :
401
- dictionary["bg_image"]=bg_image
402
- if bg_image!=None:
403
- imf=Image.open(bg_image).resize(new_size)
404
- else:
405
- with open("lotte_animation_saver/animation_4.json") as read:
406
- url_json=json.load(read)
407
- st_lottie(url_json)
408
- imf=Image.open("ALL_image_formation\home_screen.jpg").resize(new_size)
409
- else:
410
- if len(dictionary['current_image'])!=0:
411
- imf=dictionary['current_image'][0]
412
- else:
413
- with open("lotte_animation_saver/animation_4.json") as read:
414
- url_json=json.load(read)
415
- st_lottie(url_json)
416
- imf=Image.open("ALL_image_formation\home_screen.jpg")
417
-
418
- negative_image =d4_to_3d(np.array(canvas_result.image_data))
419
- if np.sum(negative_image)==0:
420
- negative_image=Image.fromarray(np.where(negative_image == False, True, negative_image))
421
- else:
422
- negative_image=Image.fromarray(negative_image)
423
-
424
- modifiedValue=model_out_put(imf,negative_image,prompt,negative_prompt)
425
- modifiedValue.save("ALL_image_formation/current_session_image.png")
426
- dictionary['current_image']=[modifiedValue]+dictionary['current_image']
427
- dictionary['every_prompt_with_val'].append((prompt,modifiedValue))
428
- st.rerun()
429
- else:
430
- st.write("nothing importent")
431
- modifiedValue="@working"
432
- dictionary['every_prompt_with_val'].append((prompt,modifiedValue))
433
- st.rerun()
434
- # st.image(modifiedValue,width=300)
435
-
436
-
437
-
438
- if canvas_result.json_data is not None:
439
- objects = pd.json_normalize(canvas_result.json_data["objects"]) # need to convert obj to str because PyArrow
440
- for col in objects.select_dtypes(include=['object']).columns:
441
- objects[col] = objects[col].astype("str")
442
-
 
1
+ import pandas as pd
2
+ from PIL import Image
3
+ import streamlit as st
4
+ import cv2
5
+ from streamlit_drawable_canvas import st_canvas
6
+ import torch
7
+ from diffusers import AutoPipelineForInpainting
8
+ import numpy as np
9
+ from streamlit_image_select import image_select
10
+ import os
11
+ import requests
12
+ from streamlit_navigation_bar import st_navbar
13
+ from langchain_community.llms import Ollama
14
+ import base64
15
+ from io import BytesIO
16
+ from PIL import Image, ImageDraw
17
+ from streamlit_lottie import st_lottie
18
+ from streamlit_option_menu import option_menu
19
+ import json
20
+ from transformers import pipeline
21
+ import streamlit as st
22
+ from streamlit_modal import Modal
23
+ import streamlit.components.v1 as components
24
+ from datetime import datetime
25
+
26
+
27
+ def image_to_base64(image_path):
28
+ with open(image_path, "rb") as img_file:
29
+ return base64.b64encode(img_file.read()).decode()
30
+
31
+
32
+ @st.cache_resource
33
+ def load_model():
34
+ pipeline_ = AutoPipelineForInpainting.from_pretrained("kandinsky-community/kandinsky-2-2-decoder-inpaint", torch_dtype=torch.float16).to("cuda")
35
+ return pipeline_
36
+
37
+ # @st.cache_resource
38
+ def prompt_improvment(pre_prompt):
39
+
40
+ llm = Ollama(model="llama3:latest",num_ctx=1000)
41
+ enhancement="Please use details from the prompt mentioned above, focusing only what user is thinking with the prompt and also add 8k resolution. Its a request only provide image description and brief prompt no other text."
42
+ prompt = pre_prompt+"\n"+enhancement
43
+ # result = llm.invoke(prompt)
44
+ return llm.stream(prompt)
45
+ def numpy_to_list(array):
46
+
47
+ current=[]
48
+ for value in array:
49
+ if isinstance(value,type(np.array([]))):
50
+ result=numpy_to_list(value)
51
+ current.append(result)
52
+ else:
53
+
54
+ current.append(int(value))
55
+ return current
56
+
57
+
58
+
59
+ @st.cache_resource
60
+ def llm_text_response():
61
+ llm = Ollama(model="llama3:latest",num_ctx=1000)
62
+ return llm.stream
63
+
64
+ def model_single_out(prompt):
65
+ pipe=load_model()
66
+ image = pipe(prompt).images[0]
67
+ return image
68
+
69
+ def model_out_put(init_image,mask_image,prompt,negative_prompt):
70
+ pipeline_ = load_model()
71
+ image = pipeline_(prompt=prompt, negative_prompt=negative_prompt, image=init_image, mask_image=mask_image).images[0]
72
+ return image
73
+
74
+ @st.cache_resource
75
+ def multimodel():
76
+ pipeline_ = pipeline("text-classification", model = "model_collection\model_4")
77
+ return pipeline_
78
+
79
+ def multimodel_output(prompt):
80
+ pipeline_ = multimodel()
81
+ image = pipeline_(prompt)
82
+ return image[0]['label']
83
+
84
+ def d4_to_3d(image):
85
+ formatted_array=[]
86
+ for j in image:
87
+ neste_list=[]
88
+ for k in j:
89
+ if any([True if i>0 else False for i in k]):
90
+ neste_list.append(True)
91
+ else:
92
+ neste_list.append(False)
93
+ formatted_array.append(neste_list)
94
+ print(np.shape(formatted_array))
95
+ return np.array(formatted_array)
96
+
97
+ st.set_page_config(layout="wide")
98
+
99
+ st.write(str(os.getcwd()))
100
+
101
+ img_selection=None
102
+ # Specify canvas parameters in application
103
+ drawing_mode = st.sidebar.selectbox(
104
+ "Drawing tool:", ("freedraw","point", "line", "rect", "circle", "transform")
105
+ )
106
+
107
+
108
+ dictionary=st.session_state
109
+ if "every_prompt_with_val" not in dictionary:
110
+ dictionary['every_prompt_with_val']=[]
111
+ if "current_image" not in dictionary:
112
+ dictionary['current_image']=[]
113
+ if "prompt_collection" not in dictionary:
114
+ dictionary['prompt_collection']=[]
115
+ if "user" not in dictionary:
116
+ dictionary['user']=None
117
+ if "current_session" not in dictionary:
118
+ dictionary['current_session']=None
119
+
120
+ stroke_width = st.sidebar.slider("Stroke width: ", 1, 25, 20)
121
+ if drawing_mode == 'point':
122
+ point_display_radius = st.sidebar.slider("Point display radius: ", 1, 25, 3)
123
+ stroke_color = '#000000'
124
+ bg_color = "#eee"
125
+
126
+
127
+ column1,column2=st.columns([0.7,0.35])
128
+
129
+ with open("\home\user\DataBase\datetimeRecords.json","r") as read:
130
+ dateTimeRecord=json.load(read)
131
+ with column2:
132
+ st.header("HISTORY")
133
+ tab1,tab2,tab3,tab4=st.tabs(["CHAT HISTORY","IMAGES","PROMPT IMPROVEMENT","LOGIN"])
134
+ with tab1:
135
+
136
+
137
+
138
+ if not len(dictionary['every_prompt_with_val']):
139
+ st.header("I will store all the chat for the current session")
140
+ with open("lotte_animation_saver\\animation_4.json") as read:
141
+ url_json=json.load(read)
142
+ st_lottie(url_json,height = 400)
143
+ else:
144
+
145
+ with st.container(height=600):
146
+
147
+
148
+ for index,prompts_ in enumerate(dictionary['every_prompt_with_val'][::-1]):
149
+ if prompts_[-1]=="@working":
150
+ if index==0:
151
+ st.write(prompts_[0].upper())
152
+ data_need=st.write_stream(llm_text_response()(prompts_[0]))
153
+ dictionary['every_prompt_with_val'][-1]=(prompts_[0],str(data_need))
154
+
155
+ elif isinstance(prompts_[-1],str):
156
+ if index==0:
157
+ st.text_area(label=prompts_[0].upper(),value=prompts_[-1],height=500)
158
+ else:
159
+ st.text_area(label=prompts_[0].upper(),value=prompts_[-1])
160
+
161
+ else:
162
+ st.write(prompts_[0].upper())
163
+ with st.container(height=400):
164
+ format1,format2=st.columns([0.2,0.8])
165
+ with format1:
166
+ new_img=Image.open("ALL_image_formation\image_gen.png")
167
+ st.write("<br>",unsafe_allow_html=True)
168
+ size = min(new_img.size)
169
+ mask = Image.new('L', (size, size), 0)
170
+ draw = ImageDraw.Draw(mask)
171
+ draw.ellipse((0, 0, size, size), fill=255)
172
+
173
+ image = new_img.crop((0, 0, size, size))
174
+ image.putalpha(mask)
175
+ st.image(image)
176
+ with format2:
177
+
178
+ st.write("<br>",unsafe_allow_html=True)
179
+ size = min(prompts_[-1].size)
180
+ mask = Image.new('L', (size, size), 0)
181
+ draw = ImageDraw.Draw(mask)
182
+ draw.ellipse((0, 0, size, size), fill=255)
183
+
184
+ # Crop the image to a square and apply the mask
185
+ image = prompts_[-1].crop((0, 0, size, size))
186
+ image.putalpha(mask)
187
+ st.image(image)
188
+
189
+ with tab2:
190
+
191
+ if "current_image" in dictionary and len(dictionary['current_image']):
192
+ with st.container(height=600):
193
+ dictinory_length=len(dictionary['current_image'])
194
+
195
+ img_selection = image_select(
196
+ label="",
197
+ images=dictionary['current_image'] if len(dictionary['current_image'])!=0 else None,
198
+ )
199
+ if img_selection in dictionary['current_image']:
200
+ dictionary['current_image'].remove(img_selection)
201
+ dictionary['current_image'].insert(0,img_selection)
202
+ # st.rerun()
203
+
204
+ img_selection.save("image.png")
205
+ with open("image.png", "rb") as file:
206
+ downl=st.download_button(label="DOWNLOAD",data=file,file_name="image.png",mime="image/png")
207
+ os.remove("image.png")
208
+ else:
209
+
210
+ st.header("This section will store the updated images")
211
+ with open("lotte_animation_saver\\animation_1.json") as read:
212
+ url_json=json.load(read)
213
+ st_lottie(url_json,height = 400)
214
+ with tab3:
215
+ if len(dictionary['prompt_collection'])!=0:
216
+ with st.container(height=600):
217
+ prompt_selection=st.selectbox(label="Select the prompt for improvment",options=["Mention below are prompt history"]+dictionary["prompt_collection"],index=0)
218
+
219
+ if prompt_selection!="Mention below are prompt history":
220
+
221
+ generated_prompt=prompt_improvment(prompt_selection)
222
+ dictionary['generated_image_prompt'].append(generated_prompt)
223
+ st.write_stream(generated_prompt)
224
+
225
+ else:
226
+
227
+ st.header("This section will provide prompt improvement section")
228
+ with open("lotte_animation_saver\\animation_3.json") as read:
229
+ url_json=json.load(read)
230
+ st_lottie(url_json,height = 400)
231
+ with tab4:
232
+
233
+ # with st.container(height=600):
234
+
235
+ if not dictionary['user'] :
236
+ with st.form("my_form"):
237
+ # st.header("Please login for save your data")
238
+ with open("lotte_animation_saver\\animation_5.json") as read:
239
+ url_json=json.load(read)
240
+ st_lottie(url_json,height = 200)
241
+ user_id = st.text_input("user login")
242
+ password = st.text_input("password",type="password")
243
+ submitted_login = st.form_submit_button("Submit")
244
+ # Every form must have a submit button.
245
+
246
+ if submitted_login:
247
+ with open("DataBase\login.json","r") as read:
248
+ login_base=json.load(read)
249
+ if user_id in login_base and login_base[user_id]==password:
250
+ dictionary['user']=user_id
251
+ st.rerun()
252
+ else:
253
+ st.error("userid or password incorrect")
254
+
255
+ st.write("working")
256
+ modal = Modal(
257
+ "Sign up",
258
+ key="demo-modal",
259
+
260
+ padding=10, # default value
261
+ max_width=600 # default value
262
+ )
263
+ open_modal = st.button("sign up")
264
+ if open_modal:
265
+ modal.open()
266
+
267
+ if modal.is_open():
268
+ with modal.container():
269
+
270
+ with st.form("my_form1"):
271
+ sign_up_column_left,sign_up_column_right=st.columns(2)
272
+ with sign_up_column_left:
273
+ with open("lotte_animation_saver\\animation_6.json") as read:
274
+ url_json=json.load(read)
275
+ st_lottie(url_json,height = 200)
276
+
277
+ with sign_up_column_right:
278
+ user_id = st.text_input("user login")
279
+ password = st.text_input("password",type="password")
280
+ submitted_signup = st.form_submit_button("Submit")
281
+
282
+ if submitted_signup:
283
+ with open("DataBase\login.json","r") as read:
284
+ login_base=json.load(read)
285
+ if not login_base:
286
+ login_base={}
287
+ if user_id not in login_base:
288
+ login_base[user_id]=password
289
+ with open("DataBase\login.json","w") as write:
290
+ json.dump(login_base,write,indent=2)
291
+ st.success("you are a part now")
292
+ dictionary['user']=user_id
293
+ modal.close()
294
+ else:
295
+ st.error("user id already exists")
296
+ else:
297
+ st.header("REPORTED ISSUES")
298
+ with st.container(height=370):
299
+
300
+ with open("DataBase\datetimeRecords.json") as feedback:
301
+ temp_issue=json.load(feedback)
302
+
303
+ arranged_feedback=reversed(temp_issue['database'])
304
+
305
+ for report in arranged_feedback:
306
+ user_columns,user_feedback=st.columns([0.3,0.8])
307
+
308
+ with user_columns:
309
+ st.write(report[-1])
310
+ with user_feedback:
311
+ st.write(report[1])
312
+
313
+ feedback=st.text_area("Feedback Report and Improvement",placeholder="")
314
+ summit=st.button("submit")
315
+ if summit:
316
+ with open("DataBase\datetimeRecords.json","r") as feedback_sumit:
317
+ temp_issue_submit=json.load(feedback_sumit)
318
+ if "database" not in temp_issue_submit:
319
+ temp_issue_submit["database"]=[]
320
+ temp_issue_submit["database"].append((str(datetime.now()),feedback,dictionary['user']))
321
+ with open("DataBase\datetimeRecords.json","w") as feedback_sumit:
322
+ json.dump(temp_issue_submit,feedback_sumit)
323
+
324
+
325
+
326
+ # st.rerun()
327
+
328
+
329
+
330
+
331
+
332
+
333
+ bg_image = st.sidebar.file_uploader("PLEASE UPLOAD IMAGE FOR EDITING:", type=["png", "jpg"])
334
+ bg_doc = st.sidebar.file_uploader("PLEASE UPLOAD DOC FOR PPT/PDF/STORY:", type=["pdf","xlsx"])
335
+
336
+
337
+ if "bg_image" not in dictionary:
338
+ dictionary["bg_image"]=None
339
+
340
+ if img_selection and dictionary['bg_image']==bg_image:
341
+ gen_image=dictionary['current_image'][0]
342
+ else:
343
+ if bg_image:
344
+ gen_image=Image.open(bg_image)
345
+ else:
346
+ gen_image=None
347
+
348
+
349
+
350
+
351
+
352
+
353
+ with column1:
354
+ # Create a canvas component
355
+ changes,implementation,current=st.columns([0.3,0.6,0.3])
356
+
357
+ with implementation:
358
+ st.write("<br>"*5,unsafe_allow_html=True)
359
+ canvas_result = st_canvas(
360
+ fill_color="rgba(255, 165, 0, 0.3)", # Fixed fill color with some opacity
361
+ stroke_width=stroke_width,
362
+ stroke_color=stroke_color,
363
+ background_color=bg_color,
364
+ background_image=gen_image if gen_image else Image.open("ALL_image_formation\image_gen.png"),
365
+ update_streamlit=True,
366
+ height=500,
367
+ width=500,
368
+ drawing_mode=drawing_mode,
369
+ point_display_radius=point_display_radius if drawing_mode == 'point' else 0,
370
+ key="canvas",
371
+ )
372
+
373
+
374
+
375
+
376
+
377
+ with column1:
378
+ # prompt=st.text_area("Please provide the prompt")
379
+ prompt=st.chat_input("Please provide the prompt")
380
+
381
+ negative_prompt="the black masked area"
382
+
383
+ # run=st.button("run_experiment")
384
+
385
+
386
+
387
+ if canvas_result.image_data is not None:
388
+ if prompt:
389
+
390
+ text_or_image=multimodel_output(prompt)
391
+
392
+ if text_or_image=="LABEL_0":
393
+
394
+ if "generated_image_prompt" not in dictionary:
395
+ dictionary['generated_image_prompt']=[]
396
+ if prompt not in dictionary['prompt_collection'] and prompt not in dictionary['generated_image_prompt']:
397
+ dictionary['prompt_collection']=[prompt]+dictionary['prompt_collection']
398
+ new_size=np.array(canvas_result.image_data).shape[:2]
399
+ new_size=(new_size[-1],new_size[0])
400
+ if bg_image!=dictionary["bg_image"] :
401
+ dictionary["bg_image"]=bg_image
402
+ if bg_image!=None:
403
+ imf=Image.open(bg_image).resize(new_size)
404
+ else:
405
+ with open("lotte_animation_saver/animation_4.json") as read:
406
+ url_json=json.load(read)
407
+ st_lottie(url_json)
408
+ imf=Image.open("ALL_image_formation\home_screen.jpg").resize(new_size)
409
+ else:
410
+ if len(dictionary['current_image'])!=0:
411
+ imf=dictionary['current_image'][0]
412
+ else:
413
+ with open("lotte_animation_saver/animation_4.json") as read:
414
+ url_json=json.load(read)
415
+ st_lottie(url_json)
416
+ imf=Image.open("ALL_image_formation\home_screen.jpg")
417
+
418
+ negative_image =d4_to_3d(np.array(canvas_result.image_data))
419
+ if np.sum(negative_image)==0:
420
+ negative_image=Image.fromarray(np.where(negative_image == False, True, negative_image))
421
+ else:
422
+ negative_image=Image.fromarray(negative_image)
423
+
424
+ modifiedValue=model_out_put(imf,negative_image,prompt,negative_prompt)
425
+ modifiedValue.save("ALL_image_formation/current_session_image.png")
426
+ dictionary['current_image']=[modifiedValue]+dictionary['current_image']
427
+ dictionary['every_prompt_with_val'].append((prompt,modifiedValue))
428
+ st.rerun()
429
+ else:
430
+ st.write("nothing importent")
431
+ modifiedValue="@working"
432
+ dictionary['every_prompt_with_val'].append((prompt,modifiedValue))
433
+ st.rerun()
434
+ # st.image(modifiedValue,width=300)
435
+
436
+
437
+
438
+ if canvas_result.json_data is not None:
439
+ objects = pd.json_normalize(canvas_result.json_data["objects"]) # need to convert obj to str because PyArrow
440
+ for col in objects.select_dtypes(include=['object']).columns:
441
+ objects[col] = objects[col].astype("str")
442
+