awacke1 commited on
Commit
b76872c
·
1 Parent(s): f413eb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -28,22 +28,18 @@ def set_model(current_model):
28
  current_model = models[current_model]
29
  return gr.update(label=(f"{current_model}"))
30
 
31
-
32
  def list_saved_prompts_and_images():
33
  saved_prompts = os.listdir('saved_prompts')
34
  saved_images = os.listdir('saved_images')
35
 
36
- prompt_image_pairs = []
37
  for prompt_file in saved_prompts:
38
- prompt_path = os.path.join('saved_prompts', prompt_file)
39
- image_path = os.path.join('saved_images', f"{prompt_file[:-4]}.png") # Remove .txt and add .png
40
- if os.path.exists(image_path):
41
- with open(prompt_path, 'r') as f:
42
- prompt = f.read()
43
- image = Image.open(image_path)
44
- prompt_image_pairs.append((prompt, image))
45
 
46
- return prompt_image_pairs
47
 
48
  def send_it1(inputs, model_choice):
49
  proc1 = models2[model_choice]
@@ -52,8 +48,8 @@ def send_it1(inputs, model_choice):
52
 
53
  # List all saved prompts and images after generating a new one
54
  prompt_image_pairs = list_saved_prompts_and_images()
55
-
56
- return output1, prompt_image_pairs
57
 
58
  css=""""""
59
 
@@ -76,6 +72,9 @@ with gr.Blocks(css=css) as myface:
76
  </head>
77
  </html>
78
  """)
 
 
 
79
  with gr.Row():
80
  with gr.Tab("Title"):
81
  gr.HTML("""<title>Prompt to Generate Image</title><div style="text-align: center; max-width: 1500px; margin: 0 auto;">
@@ -134,7 +133,7 @@ with gr.Blocks(css=css) as myface:
134
  return(inputs)
135
 
136
  model_name1.change(set_model,inputs=model_name1,outputs=[output1])
137
- run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
138
  use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
139
  see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
140
 
 
28
  current_model = models[current_model]
29
  return gr.update(label=(f"{current_model}"))
30
 
 
31
  def list_saved_prompts_and_images():
32
  saved_prompts = os.listdir('saved_prompts')
33
  saved_images = os.listdir('saved_images')
34
 
35
+ html_str = "<h2>Saved Prompts and Images:</h2><ul>"
36
  for prompt_file in saved_prompts:
37
+ image_file = f"{prompt_file[:-4]}.png"
38
+ if image_file in saved_images:
39
+ html_str += f'<li>Prompt: {prompt_file[:-4]} | <a href="saved_images/{image_file}" download>Download Image</a></li>'
40
+ html_str += "</ul>"
 
 
 
41
 
42
+ return html_str
43
 
44
  def send_it1(inputs, model_choice):
45
  proc1 = models2[model_choice]
 
48
 
49
  # List all saved prompts and images after generating a new one
50
  prompt_image_pairs = list_saved_prompts_and_images()
51
+ saved_output = list_saved_prompts_and_images()
52
+ return output1, saved_output
53
 
54
  css=""""""
55
 
 
72
  </head>
73
  </html>
74
  """)
75
+ with gr.Row():
76
+ with gr.Column(scale=100):
77
+ saved_output = gr.HTML(label="Saved Prompts and Images")
78
  with gr.Row():
79
  with gr.Tab("Title"):
80
  gr.HTML("""<title>Prompt to Generate Image</title><div style="text-align: center; max-width: 1500px; margin: 0 auto;">
 
133
  return(inputs)
134
 
135
  model_name1.change(set_model,inputs=model_name1,outputs=[output1])
136
+ run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1, saved_output])
137
  use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
138
  see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
139