Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,24 +8,22 @@ st.title("SEO Article Writer with ChatGPT")
|
|
| 8 |
|
| 9 |
|
| 10 |
def generate_article(keyword, writing_style, word_count):
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
{"role": "user", "content": "Write a SEO optimized word article about " + keyword},
|
| 16 |
{"role": "user", "content": "The article should be " + writing_style},
|
| 17 |
{"role": "user", "content": "The article length should " + str(word_count)},
|
| 18 |
]
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
return result
|
| 24 |
-
except openai.error.RateLimitError:
|
| 25 |
-
st.error("Rate limit exceeded. Waiting for 20 seconds before retrying...")
|
| 26 |
-
time.sleep(20)
|
| 27 |
-
return generate_article(keyword, writing_style, word_count)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
keyword = st.text_input("Enter a keyword:")
|
| 30 |
writing_style = st.selectbox("Select writing style:", ["Casual", "Informative", "Professional"])
|
| 31 |
word_count = st.slider("Select word count:", min_value=1000, max_value=10000, step=100, value=3000)
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def generate_article(keyword, writing_style, word_count):
|
| 11 |
+
#return "This is a test article generated without making API calls."
|
| 12 |
+
response = openai.ChatCompletion.create(
|
| 13 |
+
model="gpt-3.5-turbo",
|
| 14 |
+
messages=[
|
| 15 |
{"role": "user", "content": "Write a SEO optimized word article about " + keyword},
|
| 16 |
{"role": "user", "content": "The article should be " + writing_style},
|
| 17 |
{"role": "user", "content": "The article length should " + str(word_count)},
|
| 18 |
]
|
| 19 |
+
)
|
| 20 |
+
result = ''
|
| 21 |
+
for choice in response.choices:
|
| 22 |
+
result += choice.message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
print(result)
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
keyword = st.text_input("Enter a keyword:")
|
| 28 |
writing_style = st.selectbox("Select writing style:", ["Casual", "Informative", "Professional"])
|
| 29 |
word_count = st.slider("Select word count:", min_value=1000, max_value=10000, step=100, value=3000)
|