ysharma HF staff commited on
Commit
817f443
1 Parent(s): d097c3a
Files changed (1) hide show
  1. app.py +8 -33
app.py CHANGED
@@ -12,27 +12,6 @@ HF_TOKEN = os.environ["HF_TOKEN"]
12
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
13
 
14
 
15
- prompt1 = """
16
- word: risk
17
- poem using word: And then the day came,
18
- when the risk
19
- to remain tight
20
- in a bud
21
- was more painful
22
- than the risk
23
- it took
24
- to blossom.
25
- word: """
26
-
27
- prompt2 = """
28
- Q: Joy has 5 balls. He buys 2 more cans of balls. Each can has 3 balls. How many balls he has now?
29
- A: Joy had 5 balls. 2 cans of 3 balls each is 6 balls. 5 + 6 = 11. Answer is 11.
30
- Q: Jane has 16 balls. Half balls are golf balls, and half golf balls are red. How many red golf balls are there?
31
- A: """
32
-
33
- prompt3 = """Q: A juggler can juggle 16 balls. Half of the balls are golf balls, and half of the golf balls are blue. How many blue golf balls are there?
34
- A: Let’s think step by step.
35
- """
36
  #Complete below sentence in fun way.
37
  prompt4 = """Distracted from: hubble
38
  by: james webb
@@ -96,7 +75,7 @@ def write_on_image(final_solution):
96
 
97
  return image0, new_prompt
98
 
99
- def meme_generate(img, prompt): #prompt, generated_txt): #, input_prompt_sql ): #, input_prompt_dalle2):
100
 
101
  print(f"*****Inside meme_generate - Prompt is :{prompt}")
102
  if len(prompt) == 0:
@@ -106,10 +85,10 @@ def meme_generate(img, prompt): #prompt, generated_txt): #, input_prompt_sql ):
106
  "parameters":
107
  {
108
  #"top_p": 0.95,
109
- "top_p": 0.90,
110
  #"top_k":0,
111
  "max_new_tokens": 250,
112
- "temperature": 1.1,
113
  #"num_return_sequences": 3,
114
  "return_full_text": True,
115
  "do_sample": True,
@@ -126,14 +105,6 @@ def meme_generate(img, prompt): #prompt, generated_txt): #, input_prompt_sql ):
126
  print(f"output_tmp is: {output_tmp}")
127
  solution = output_tmp.split("\nQ:")[0]
128
  print(f"Final response after splits is: {solution}")
129
- #if '\nOutput:' in solution:
130
- # final_solution = solution.split("\nOutput:")[0]
131
- # print(f"Response after removing output is: {final_solution}")
132
- #elif '\n\n' in solution:
133
- # final_solution = solution.split("\n\n")[0]
134
- # print(f"Response after removing new line entries is: {final_solution}")
135
- #else:
136
- #final_solution = solution
137
 
138
  meme_image, new_prompt = write_on_image(solution)
139
  return meme_image, new_prompt #final_solution #display_output, new_prompt #generated_txt+prompt
@@ -168,12 +139,16 @@ with demo:
168
 
169
  #with gr.Row():
170
  output_image = gr.Image() #type="filepath", shape=(256,256))
 
 
 
 
171
  #output_prompt = gr.Textbox(label="Text generated", lines=5)
172
 
173
  b1 = gr.Button("Generate")
174
  #b2 = gr.Button("Generate Image")
175
 
176
- b1.click(meme_generate, inputs=[in_image, input_prompt] , outputs=[output_image,input_prompt]) #output_prompt
177
  #b2.click(poem_to_image, poem_txt, output_image)
178
  #examples=examples
179
 
12
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
13
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  #Complete below sentence in fun way.
16
  prompt4 = """Distracted from: hubble
17
  by: james webb
75
 
76
  return image0, new_prompt
77
 
78
+ def meme_generate(img, prompt, temp, top_p): #prompt, generated_txt): #, input_prompt_sql ): #, input_prompt_dalle2):
79
 
80
  print(f"*****Inside meme_generate - Prompt is :{prompt}")
81
  if len(prompt) == 0:
85
  "parameters":
86
  {
87
  #"top_p": 0.95,
88
+ "top_p": top_p, #0.90,
89
  #"top_k":0,
90
  "max_new_tokens": 250,
91
+ "temperature": temp, #1.1,
92
  #"num_return_sequences": 3,
93
  "return_full_text": True,
94
  "do_sample": True,
105
  print(f"output_tmp is: {output_tmp}")
106
  solution = output_tmp.split("\nQ:")[0]
107
  print(f"Final response after splits is: {solution}")
 
 
 
 
 
 
 
 
108
 
109
  meme_image, new_prompt = write_on_image(solution)
110
  return meme_image, new_prompt #final_solution #display_output, new_prompt #generated_txt+prompt
139
 
140
  #with gr.Row():
141
  output_image = gr.Image() #type="filepath", shape=(256,256))
142
+ with gr.Row():
143
+ in_slider_temp = gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label='Temperature')
144
+ in_slider_top_p = gr.Slider(minimum=0.50, maximum=0.99, value=0.90, step=0.01, label='Top_p')
145
+
146
  #output_prompt = gr.Textbox(label="Text generated", lines=5)
147
 
148
  b1 = gr.Button("Generate")
149
  #b2 = gr.Button("Generate Image")
150
 
151
+ b1.click(meme_generate, inputs=[in_image, input_prompt, in_slider_temp, in_slider_top_p] , outputs=[output_image,input_prompt]) #output_prompt
152
  #b2.click(poem_to_image, poem_txt, output_image)
153
  #examples=examples
154