Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,37 @@ word: """
|
|
| 24 |
examples = [["river"], ["night"], ["trees"],["table"],["laughs"]]
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
def poem_generate(word):
|
| 28 |
|
| 29 |
p = prompt + word.lower() + "\n" + "poem using word: "
|
|
@@ -79,7 +110,7 @@ with demo:
|
|
| 79 |
b1 = gr.Button("Generate Poem")
|
| 80 |
b2 = gr.Button("Generate Image")
|
| 81 |
|
| 82 |
-
b1.click(
|
| 83 |
b2.click(poem_to_image, poem_txt, output_image)
|
| 84 |
#examples=examples
|
| 85 |
|
|
|
|
| 24 |
examples = [["river"], ["night"], ["trees"],["table"],["laughs"]]
|
| 25 |
|
| 26 |
|
| 27 |
+
def poem2_generate(word):
|
| 28 |
+
p = word.lower() + "\n" + "poem using word: "
|
| 29 |
+
print(f"*****Inside poem_generate - Prompt is :{p}")
|
| 30 |
+
json_ = {"inputs": p,
|
| 31 |
+
"parameters":
|
| 32 |
+
{
|
| 33 |
+
"top_p": 0.9,
|
| 34 |
+
"temperature": 1.1,
|
| 35 |
+
"max_new_tokens": 50,
|
| 36 |
+
"return_full_text": False
|
| 37 |
+
}}
|
| 38 |
+
response = requests.post(API_URL, headers=headers, json=json_)
|
| 39 |
+
output = response.json()
|
| 40 |
+
print(f"If there was an error? Reason is : {output}")
|
| 41 |
+
output_tmp = output[0]['generated_text']
|
| 42 |
+
print(f"GPTJ response without splits is: {output_tmp}")
|
| 43 |
+
#poem = output[0]['generated_text'].split("\n\n")[0] # +"."
|
| 44 |
+
if "\n\n" not in output_tmp:
|
| 45 |
+
if output_tmp.find('.') != -1:
|
| 46 |
+
idx = output_tmp.find('.')
|
| 47 |
+
poem = output_tmp[:idx+1]
|
| 48 |
+
else:
|
| 49 |
+
idx = output_tmp.rfind('\n')
|
| 50 |
+
poem = output_tmp[:idx]
|
| 51 |
+
else:
|
| 52 |
+
poem = output_tmp.split("\n\n")[0] # +"."
|
| 53 |
+
poem = poem.replace('?','')
|
| 54 |
+
print(f"Poem being returned is: {poem}")
|
| 55 |
+
return poem
|
| 56 |
+
|
| 57 |
+
|
| 58 |
def poem_generate(word):
|
| 59 |
|
| 60 |
p = prompt + word.lower() + "\n" + "poem using word: "
|
|
|
|
| 110 |
b1 = gr.Button("Generate Poem")
|
| 111 |
b2 = gr.Button("Generate Image")
|
| 112 |
|
| 113 |
+
b1.click(poem2_generate, input_word, poem_txt)
|
| 114 |
b2.click(poem_to_image, poem_txt, output_image)
|
| 115 |
#examples=examples
|
| 116 |
|