awacke1 commited on
Commit
a58a516
·
1 Parent(s): 67ed819

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -105,6 +105,8 @@ def text_generate_old(prompt, generated_txt):
105
  {"use_cache": True,
106
  "wait_for_model": True,
107
  },}
 
 
108
  response = requests.post(API_URL, headers=headers, json=json_)
109
  print(f"Response is : {response}")
110
  output = response.json()
@@ -113,6 +115,8 @@ def text_generate_old(prompt, generated_txt):
113
  print(f"output_tmp is: {output_tmp}")
114
  solution = output_tmp.split("\nQ:")[0]
115
  print(f"Final response after splits is: {solution}")
 
 
116
  if '\nOutput:' in solution:
117
  final_solution = solution.split("\nOutput:")[0]
118
  print(f"Response after removing output is: {final_solution}")
@@ -121,18 +125,18 @@ def text_generate_old(prompt, generated_txt):
121
  print(f"Response after removing new line entries is: {final_solution}")
122
  else:
123
  final_solution = solution
124
-
125
-
126
  if len(generated_txt) == 0 :
127
  display_output = final_solution
128
  else:
129
  display_output = generated_txt[:-len(prompt)] + final_solution
 
 
130
  new_prompt = final_solution[len(prompt):]
131
- print(f"new prompt for next cycle is : {new_prompt}")
132
- print(f"display_output for printing on screen is : {display_output}")
133
  if len(new_prompt) == 0:
134
  temp_text = display_output[::-1]
135
- print(f"What is the last character of sentence? : {temp_text[0]}")
136
  if temp_text[1] == '.':
137
  first_period_loc = temp_text[2:].find('.') + 1
138
  print(f"Location of last Period is: {first_period_loc}")
@@ -141,28 +145,20 @@ def text_generate_old(prompt, generated_txt):
141
  else:
142
  print("HERE")
143
  first_period_loc = temp_text.find('.')
144
- print(f"Location of last Period is : {first_period_loc}")
145
  new_prompt = display_output[-first_period_loc:-1]
146
- print(f"Not sending blank as prompt so new prompt for next cycle is : {new_prompt}")
147
  display_output = display_output[:-1]
148
-
149
  return display_output, new_prompt
150
 
151
-
152
  demo = gr.Blocks()
153
-
154
  with demo:
155
  with gr.Row():
156
  input_prompt = gr.Textbox(label="Write some text to get started...", lines=3, value="Dear human philosophers, I read your comments on my abilities and limitations with great interest.")
157
-
158
  with gr.Row():
159
  generated_txt = gr.Textbox(lines=5, visible = True)
160
-
161
  with gr.Row():
162
  Thoughts = gr.Textbox(lines=10, visible = True)
163
-
164
- b1 = gr.Button("Generate Your Story")
165
-
166
- b1.click(text_generate, inputs=[input_prompt, generated_txt], outputs=[generated_txt, input_prompt, Thoughts])
167
-
168
  demo.launch(enable_queue=True, debug=True)
 
105
  {"use_cache": True,
106
  "wait_for_model": True,
107
  },}
108
+
109
+
110
  response = requests.post(API_URL, headers=headers, json=json_)
111
  print(f"Response is : {response}")
112
  output = response.json()
 
115
  print(f"output_tmp is: {output_tmp}")
116
  solution = output_tmp.split("\nQ:")[0]
117
  print(f"Final response after splits is: {solution}")
118
+
119
+
120
  if '\nOutput:' in solution:
121
  final_solution = solution.split("\nOutput:")[0]
122
  print(f"Response after removing output is: {final_solution}")
 
125
  print(f"Response after removing new line entries is: {final_solution}")
126
  else:
127
  final_solution = solution
 
 
128
  if len(generated_txt) == 0 :
129
  display_output = final_solution
130
  else:
131
  display_output = generated_txt[:-len(prompt)] + final_solution
132
+
133
+
134
  new_prompt = final_solution[len(prompt):]
135
+ print(f"New prompt for next cycle: {new_prompt}")
136
+ print(f"Output final is : {display_output}")
137
  if len(new_prompt) == 0:
138
  temp_text = display_output[::-1]
139
+ print(f"Last character of sentence: {temp_text[0]}")
140
  if temp_text[1] == '.':
141
  first_period_loc = temp_text[2:].find('.') + 1
142
  print(f"Location of last Period is: {first_period_loc}")
 
145
  else:
146
  print("HERE")
147
  first_period_loc = temp_text.find('.')
148
+ print(f"Last Period is : {first_period_loc}")
149
  new_prompt = display_output[-first_period_loc:-1]
150
+ print(f"New prompt for next cycle is : {new_prompt}")
151
  display_output = display_output[:-1]
 
152
  return display_output, new_prompt
153
 
 
154
  demo = gr.Blocks()
 
155
  with demo:
156
  with gr.Row():
157
  input_prompt = gr.Textbox(label="Write some text to get started...", lines=3, value="Dear human philosophers, I read your comments on my abilities and limitations with great interest.")
 
158
  with gr.Row():
159
  generated_txt = gr.Textbox(lines=5, visible = True)
 
160
  with gr.Row():
161
  Thoughts = gr.Textbox(lines=10, visible = True)
162
+ generate = gr.Button("Generate")
163
+ generate.click(text_generate, inputs=[input_prompt, generated_txt], outputs=[generated_txt, input_prompt, Thoughts])
 
 
 
164
  demo.launch(enable_queue=True, debug=True)