app.py
CHANGED
|
@@ -3,26 +3,26 @@ import requests
|
|
| 3 |
|
| 4 |
# GPT-J-6B API
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
| 7 |
#examples = [["the roads are lovely dark and deep"], ["to be or not to be is the question, isn't it"], ["Elon Musk is not sure about "]]
|
| 8 |
|
| 9 |
|
| 10 |
def poem_generate(word):
|
| 11 |
-
|
| 12 |
-
word:
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
to remain tight
|
| 16 |
-
in a bud
|
| 17 |
-
was more painful
|
| 18 |
-
than the risk
|
| 19 |
-
it took
|
| 20 |
-
to blossom.
|
| 21 |
-
|
| 22 |
-
word: """
|
| 23 |
-
prompt = prompt + word.lower() + "\n" + "poem using word: "
|
| 24 |
-
print(f"Prompt is :{prompt}")
|
| 25 |
-
json_ = {"inputs": prompt,
|
| 26 |
"parameters":
|
| 27 |
{
|
| 28 |
"top_p": 0.9,
|
|
@@ -33,7 +33,7 @@ def poem_generate(word):
|
|
| 33 |
response = requests.post(API_URL, json=json_)
|
| 34 |
output = response.json()
|
| 35 |
print(f"Poem without splits is: {output[0]['generated_text']}")
|
| 36 |
-
poem = output[0]['generated_text'].split("\n
|
| 37 |
|
| 38 |
return poem
|
| 39 |
|
|
|
|
| 3 |
|
| 4 |
# GPT-J-6B API
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
|
| 6 |
+
prompt = """
|
| 7 |
+
word: risk
|
| 8 |
+
poem using word: And then the day came,
|
| 9 |
+
when the risk
|
| 10 |
+
to remain tight
|
| 11 |
+
in a bud
|
| 12 |
+
was more painful
|
| 13 |
+
than the risk
|
| 14 |
+
it took
|
| 15 |
+
to blossom.
|
| 16 |
|
| 17 |
+
word: """
|
| 18 |
#examples = [["the roads are lovely dark and deep"], ["to be or not to be is the question, isn't it"], ["Elon Musk is not sure about "]]
|
| 19 |
|
| 20 |
|
| 21 |
def poem_generate(word):
|
| 22 |
+
|
| 23 |
+
p = prompt + word.lower() + "\n" + "poem using word: "
|
| 24 |
+
print(f"Prompt is :{p}")
|
| 25 |
+
json_ = {"inputs": p,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
"parameters":
|
| 27 |
{
|
| 28 |
"top_p": 0.9,
|
|
|
|
| 33 |
response = requests.post(API_URL, json=json_)
|
| 34 |
output = response.json()
|
| 35 |
print(f"Poem without splits is: {output[0]['generated_text']}")
|
| 36 |
+
poem = output[0]['generated_text'].split("\n\n")[0] # +"."
|
| 37 |
|
| 38 |
return poem
|
| 39 |
|