Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
|
@@ -43,16 +43,55 @@ by: new goals
|
|
| 43 |
Distracted from:
|
| 44 |
"""
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def write_on_image(final_solution):
|
| 47 |
print("************ Inside write_on_image ***********")
|
| 48 |
image_path0 = "./distracted0.jpg"
|
| 49 |
image0 = Image.open(image_path0)
|
| 50 |
I1 = ImageDraw.Draw(image0)
|
| 51 |
myfont = ImageFont.truetype('./font1.ttf', 30)
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
I1.text((371, 223), "ME", font=myfont, fill =(255, 255, 255))
|
| 54 |
-
I1.text((142, 336),
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
def meme_generate(img, prompt): #prompt, generated_txt): #, input_prompt_sql ): #, input_prompt_dalle2):
|
| 58 |
|
|
@@ -81,17 +120,17 @@ def meme_generate(img, prompt): #prompt, generated_txt): #, input_prompt_sql ):
|
|
| 81 |
print(f"output_tmp is: {output_tmp}")
|
| 82 |
solution = output_tmp.split("\nQ:")[0]
|
| 83 |
print(f"Final response after splits is: {solution}")
|
| 84 |
-
if '\nOutput:' in solution:
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
elif '\n\n' in solution:
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
else:
|
| 91 |
-
|
| 92 |
|
| 93 |
-
meme_image = write_on_image(
|
| 94 |
-
return meme_image,
|
| 95 |
|
| 96 |
|
| 97 |
demo = gr.Blocks()
|
|
@@ -114,8 +153,10 @@ with demo:
|
|
| 114 |
#"Dalle Prompt: Cyberwave vaporpunk art of a kneeling figure, looking up at a glowing neon book icon, smoke and mist, pink and blue lighting, cybernetic sci-fi render\nNew Dalle Prompt: " ], label= "Choose a sample Prompt")
|
| 115 |
|
| 116 |
#with gr.Row():
|
| 117 |
-
in_image = gr.Image(value="./distracted0.jpg")
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
#input_prompt_dalle2 = gr.Textbox(label="Or Write sample Dalle2 prompts to get more Prompt ideas...")
|
| 120 |
#input_prompt2 = gr.Textbox(label="Write some text to get started...", lines=3, visible=False) #input_prompt_sql
|
| 121 |
|
|
@@ -125,12 +166,12 @@ with demo:
|
|
| 125 |
|
| 126 |
with gr.Row():
|
| 127 |
output_image = gr.Image() #type="filepath", shape=(256,256))
|
| 128 |
-
output_prompt = gr.Textbox(label="Text generated", lines=5)
|
| 129 |
|
| 130 |
b1 = gr.Button("Generate")
|
| 131 |
#b2 = gr.Button("Generate Image")
|
| 132 |
|
| 133 |
-
b1.click(meme_generate, inputs=[in_image, input_prompt], outputs=[output_image,
|
| 134 |
#b2.click(poem_to_image, poem_txt, output_image)
|
| 135 |
#examples=examples
|
| 136 |
|
|
|
|
| 43 |
Distracted from:
|
| 44 |
"""
|
| 45 |
|
| 46 |
+
prompt5 = """Distracted from: homework
|
| 47 |
+
by: side project
|
| 48 |
+
Distracted from: goals
|
| 49 |
+
by: new goals
|
| 50 |
+
Distracted from: working hard
|
| 51 |
+
by: hardly working
|
| 52 |
+
Distracted from: twitter
|
| 53 |
+
by: open in browser
|
| 54 |
+
Distracted from:
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
"""Distracted from: homework
|
| 58 |
+
by: side project
|
| 59 |
+
Distracted from: goals
|
| 60 |
+
by: new goals
|
| 61 |
+
Distracted from: working hard
|
| 62 |
+
by: hardly working
|
| 63 |
+
Distracted from: twitter
|
| 64 |
+
by: open in browser
|
| 65 |
+
Distracted from: code
|
| 66 |
+
by: blog post
|
| 67 |
+
Distracted from: code
|
| 68 |
+
by: blog post
|
| 69 |
+
Distracted from:"""
|
| 70 |
+
|
| 71 |
+
|
| 72 |
def write_on_image(final_solution):
|
| 73 |
print("************ Inside write_on_image ***********")
|
| 74 |
image_path0 = "./distracted0.jpg"
|
| 75 |
image0 = Image.open(image_path0)
|
| 76 |
I1 = ImageDraw.Draw(image0)
|
| 77 |
myfont = ImageFont.truetype('./font1.ttf', 30)
|
| 78 |
+
|
| 79 |
+
prompt_list = final_solution.split('\n')
|
| 80 |
+
girlfriend = prompt_list[8].split(':')[1].strip()
|
| 81 |
+
new_girl = prompt_list[9].split(':')[1].strip()
|
| 82 |
+
prompt_list.pop(0)
|
| 83 |
+
prompt_list.pop(1)
|
| 84 |
+
prompt_list = prompt_list[:7]
|
| 85 |
+
prompt_list[8] = 'Distracted from:'
|
| 86 |
+
print(f"prompt list is : {prompt_list}")
|
| 87 |
+
new_prompt = '\n'.join(prompt_list)
|
| 88 |
+
print(f"final_solution is : {new_prompt}")
|
| 89 |
+
|
| 90 |
+
I1.text((613, 89), girlfriend,font=myfont, fill =(255, 255, 255))
|
| 91 |
I1.text((371, 223), "ME", font=myfont, fill =(255, 255, 255))
|
| 92 |
+
I1.text((142, 336), new_girl,font=myfont, fill =(255, 255, 255))
|
| 93 |
+
|
| 94 |
+
return image0, new_prompt
|
| 95 |
|
| 96 |
def meme_generate(img, prompt): #prompt, generated_txt): #, input_prompt_sql ): #, input_prompt_dalle2):
|
| 97 |
|
|
|
|
| 120 |
print(f"output_tmp is: {output_tmp}")
|
| 121 |
solution = output_tmp.split("\nQ:")[0]
|
| 122 |
print(f"Final response after splits is: {solution}")
|
| 123 |
+
#if '\nOutput:' in solution:
|
| 124 |
+
# final_solution = solution.split("\nOutput:")[0]
|
| 125 |
+
# print(f"Response after removing output is: {final_solution}")
|
| 126 |
+
#elif '\n\n' in solution:
|
| 127 |
+
# final_solution = solution.split("\n\n")[0]
|
| 128 |
+
# print(f"Response after removing new line entries is: {final_solution}")
|
| 129 |
+
#else:
|
| 130 |
+
#final_solution = solution
|
| 131 |
|
| 132 |
+
meme_image, new_prompt = write_on_image(solution)
|
| 133 |
+
return meme_image, solution #final_solution #display_output, new_prompt #generated_txt+prompt
|
| 134 |
|
| 135 |
|
| 136 |
demo = gr.Blocks()
|
|
|
|
| 153 |
#"Dalle Prompt: Cyberwave vaporpunk art of a kneeling figure, looking up at a glowing neon book icon, smoke and mist, pink and blue lighting, cybernetic sci-fi render\nNew Dalle Prompt: " ], label= "Choose a sample Prompt")
|
| 154 |
|
| 155 |
#with gr.Row():
|
| 156 |
+
in_image = gr.Image(value="./distracted0.jpg", visible=False)
|
| 157 |
+
in_image_display = gr.Image(value="./distracted00.jpg", visible=True)
|
| 158 |
+
input_prompt = gr.Textbox(label="Write some prompt...", lines=5,
|
| 159 |
+
value = """Distracted from: homework\nby: side project\nDistracted from: goals\nby: new goals\nDistracted from: working hard\nby: hardly working\nDistracted from: twitter\nby: open in browser\nDistracted from:""", visible=False) #input_prompt_sql
|
| 160 |
#input_prompt_dalle2 = gr.Textbox(label="Or Write sample Dalle2 prompts to get more Prompt ideas...")
|
| 161 |
#input_prompt2 = gr.Textbox(label="Write some text to get started...", lines=3, visible=False) #input_prompt_sql
|
| 162 |
|
|
|
|
| 166 |
|
| 167 |
with gr.Row():
|
| 168 |
output_image = gr.Image() #type="filepath", shape=(256,256))
|
| 169 |
+
#output_prompt = gr.Textbox(label="Text generated", lines=5)
|
| 170 |
|
| 171 |
b1 = gr.Button("Generate")
|
| 172 |
#b2 = gr.Button("Generate Image")
|
| 173 |
|
| 174 |
+
b1.click(meme_generate, inputs=[in_image, input_prompt], outputs=[output_image,input_prompt]) #output_prompt
|
| 175 |
#b2.click(poem_to_image, poem_txt, output_image)
|
| 176 |
#examples=examples
|
| 177 |
|