Spaces:
Runtime error
Runtime error
Commit
·
369b102
1
Parent(s):
487de19
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,16 +8,17 @@ API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
|
|
| 8 |
headers = {"Authorization": f"Bearer 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"}
|
| 9 |
|
| 10 |
|
| 11 |
-
def text_generate(prompt,
|
| 12 |
#Prints to debug the code
|
| 13 |
print(f"*****Inside text_generate - Prompt is :{prompt}")
|
| 14 |
-
|
|
|
|
| 15 |
"parameters":
|
| 16 |
{
|
| 17 |
"top_p": float(top_p),
|
| 18 |
"top_k": top_k,
|
| 19 |
"temperature": float(temperature),
|
| 20 |
-
"max_new_tokens":
|
| 21 |
"return_full_text": True,
|
| 22 |
"do_sample":True,
|
| 23 |
"num_beams": num_beams,
|
|
@@ -45,31 +46,31 @@ def text_generate(prompt, generated_txt, top_p=0.8, top_k=100, temperature=1.0,
|
|
| 45 |
else:
|
| 46 |
final_solution = solution
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
else:
|
| 52 |
-
display_output = generated_txt[:-len(prompt)] + final_solution
|
| 53 |
-
new_prompt = final_solution[len(prompt):]
|
| 54 |
-
print(f"new prompt for next cycle is : {new_prompt}")
|
| 55 |
-
print(f"display_output for printing on screen is : {display_output}")
|
| 56 |
-
if len(new_prompt) == 0:
|
| 57 |
-
temp_text = display_output[::-1]
|
| 58 |
-
print(f"What is the last character of sentence? : {temp_text[0]}")
|
| 59 |
-
if temp_text[1] == '.':
|
| 60 |
-
first_period_loc = temp_text[2:].find('.') + 1
|
| 61 |
-
print(f"Location of last Period is: {first_period_loc}")
|
| 62 |
-
new_prompt = display_output[-first_period_loc:-1]
|
| 63 |
-
print(f"Not sending blank as prompt so new prompt for next cycle is : {new_prompt}")
|
| 64 |
else:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
demo = gr.Blocks()
|
|
@@ -104,6 +105,7 @@ with demo:
|
|
| 104 |
|
| 105 |
b1 = gr.Button("Generate Your Story")
|
| 106 |
|
| 107 |
-
b1.click(text_generate, inputs=[input_prompt, generated_txt, top_p, top_k, temperature, num_beams, repetition_penalty], outputs=[generated_txt, input_prompt])
|
|
|
|
| 108 |
|
| 109 |
demo.launch(enable_queue=True, debug=True)
|
|
|
|
| 8 |
headers = {"Authorization": f"Bearer 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"}
|
| 9 |
|
| 10 |
|
| 11 |
+
def text_generate(prompt, top_p=0.8, top_k=100, temperature=1.0, num_beams=3, repetition_penalty=3.0):
|
| 12 |
#Prints to debug the code
|
| 13 |
print(f"*****Inside text_generate - Prompt is :{prompt}")
|
| 14 |
+
max_tokens = 250
|
| 15 |
+
json_ = {"inputs": prompt[-max_tokens:],
|
| 16 |
"parameters":
|
| 17 |
{
|
| 18 |
"top_p": float(top_p),
|
| 19 |
"top_k": top_k,
|
| 20 |
"temperature": float(temperature),
|
| 21 |
+
"max_new_tokens": max_tokens,
|
| 22 |
"return_full_text": True,
|
| 23 |
"do_sample":True,
|
| 24 |
"num_beams": num_beams,
|
|
|
|
| 46 |
else:
|
| 47 |
final_solution = solution
|
| 48 |
|
| 49 |
+
if 0:
|
| 50 |
+
if len(generated_txt) == 0 :
|
| 51 |
+
display_output = final_solution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
else:
|
| 53 |
+
display_output = generated_txt[:-len(prompt)] + final_solution
|
| 54 |
+
new_prompt = final_solution[len(prompt):]
|
| 55 |
+
print(f"new prompt for next cycle is : {new_prompt}")
|
| 56 |
+
print(f"display_output for printing on screen is : {display_output}")
|
| 57 |
+
if len(new_prompt) == 0:
|
| 58 |
+
temp_text = display_output[::-1]
|
| 59 |
+
print(f"What is the last character of sentence? : {temp_text[0]}")
|
| 60 |
+
if temp_text[1] == '.':
|
| 61 |
+
first_period_loc = temp_text[2:].find('.') + 1
|
| 62 |
+
print(f"Location of last Period is: {first_period_loc}")
|
| 63 |
+
new_prompt = display_output[-first_period_loc:-1]
|
| 64 |
+
print(f"Not sending blank as prompt so new prompt for next cycle is : {new_prompt}")
|
| 65 |
+
else:
|
| 66 |
+
print("HERE")
|
| 67 |
+
first_period_loc = temp_text.find('.')
|
| 68 |
+
print(f"Location of last Period is : {first_period_loc}")
|
| 69 |
+
new_prompt = display_output[-first_period_loc:-1]
|
| 70 |
+
print(f"Not sending blank as prompt so new prompt for next cycle is : {new_prompt}")
|
| 71 |
+
display_output = display_output[:-1]
|
| 72 |
+
|
| 73 |
+
return final_solution
|
| 74 |
|
| 75 |
|
| 76 |
demo = gr.Blocks()
|
|
|
|
| 105 |
|
| 106 |
b1 = gr.Button("Generate Your Story")
|
| 107 |
|
| 108 |
+
# b1.click(text_generate, inputs=[input_prompt, generated_txt, top_p, top_k, temperature, num_beams, repetition_penalty], outputs=[generated_txt, input_prompt])
|
| 109 |
+
b1.click(text_generate, inputs=[input_prompt, top_p, top_k, temperature, num_beams, repetition_penalty], outputs=[input_prompt])
|
| 110 |
|
| 111 |
demo.launch(enable_queue=True, debug=True)
|