Dede16 commited on
Commit
b40ed65
·
1 Parent(s): 598879f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +141 -186
app.py CHANGED
@@ -65,80 +65,59 @@ def clean_scrap(artikel,link, openai_key):
65
  article = []
66
  if len(artikel) > 1:
67
  for art in artikel:
68
- @retry(openai.error.OpenAIError, tries=10, delay=10)
69
- openai.api_key = openai_key
70
- try:
71
- response = openai.ChatCompletion.create(
72
- model ="gpt-3.5-turbo",
73
- messages=[
74
- {"role": "system", "content": "You are a very professional article editor."},
75
- {"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains. \nThen, you should also summarize the article so that it does not exceed 5000 characters" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned and summarized article's content}"}
76
- ],
77
- temperature = 0.1
78
- )
79
- finish_reason = response['choices'][0]['finish_reason']
80
- if finish_reason == 'length' or finish_reason == 'stop':
81
- result = response['choices'][0]['message']['content']
82
- new_artikel.append(result)
83
- except openai.error.OpenAIError as e:
84
- print('server sibuk')
85
  else:
86
- for art in artikel:
87
- @retry(openai.error.OpenAIError, tries=10, delay=10)
88
- openai.api_key = openai_key
89
- try:
90
- response = openai.ChatCompletion.create(
91
- model ="gpt-3.5-turbo",
92
- messages=[
93
- {"role": "system", "content": "You are a very professional article editor."},
94
- {"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains." + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned article's content}"}
95
- ],
96
- temperature = 0.1
97
- )
98
- finish_reason = response['choices'][0]['finish_reason']
99
- if finish_reason == 'length' or finish_reason == 'stop':
100
- result = response['choices'][0]['message']['content']
101
- new_artikel.append(result)
102
- except openai.error.OpenAIError as e:
103
- print('server sibuk')
104
-
105
- new_art = [' '.join(new_artikel)]
106
- for art in new_art:
107
- @retry(openai.error.OpenAIError, tries=10, delay=10)
108
- openai.api_key = openai_key
109
- try:
110
  response = openai.ChatCompletion.create(
111
  model ="gpt-3.5-turbo",
112
  messages=[
113
- {"role": "system", "content": "You are a very professional article editor and capable of generating compelling and professional article titles."},
114
- {"role": "user", "content": "Paraphrase the above article to make it a well-written and easily understandable piece for humans, following the conventions of renowned articles. \nThen, You Must Generate a title that is appropriate for the article I provided. The title should be professional, similar to typical article titles and sound more natural for a human to read" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: title:{title}, article: {new paraphrased article}"}
115
- ],
116
  temperature = 0.1
117
  )
118
  finish_reason = response['choices'][0]['finish_reason']
119
  if finish_reason == 'length' or finish_reason == 'stop':
120
  result = response['choices'][0]['message']['content']
121
- article.append(result)
122
- except openai.error.OpenAIError as e:
123
- print('server sibuk')
124
 
125
- content = article[0].split("\n")
126
- title = content[0].replace('title:', '').replace("Title:", '').strip()
127
- @retry(openai.error.OpenAIError, tries=10, delay=10)
128
- openai.api_key = openai_key
129
- try:
130
  response = openai.ChatCompletion.create(
131
  model ="gpt-3.5-turbo",
132
  messages=[
133
- {"role": "system", "content": "You are a professional translator and rewriter"},
134
- {"role": "user", "content": "Please translate and rewrite this sentence into Indonesian language with the following requirements: \n1. The sentence should be concise, compact, and clear. \n2. The sentence length should not exceed 50 characters. \n3. The sentences should be professional, similar to typical article titles and sound more natural for a human to read.:" +title+"\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: Judul:{hasil rewrite}"}
135
- ],
136
- temperature = 0
137
  )
138
- judul = response['choices'][0]['message']['content']
139
- except openai.error.OpenAIError as e:
140
- print('server sibuk')
141
-
 
 
 
 
 
 
 
 
 
 
 
 
142
  judul = judul.replace("Judul:", '').strip()
143
  judul = judul.replace("Title:", '').strip()
144
  try:
@@ -196,132 +175,108 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
196
  post_article = []
197
 
198
  for i in artikel:
199
- @retry(openai.error.OpenAIError, tries=10, delay=10)
200
- openai.api_key = openai_key
201
- try:
202
- response = openai.ChatCompletion.create(
203
- model ="gpt-3.5-turbo",
204
- messages=[
205
- {"role": "system", "content": "You are a proficient English to Indonesian language translator machine. You are capable of translating professionally according to the rules of the Indonesian language"},
206
- {"role": "user", "content": "Translate the following article into Indonesian language. Then, you must resume the article translated. The translated result should be more than 2500 characters and less than 7000 characters.: " + i + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {Professionally rewritten content}"}
207
- ],
208
- temperature = 0
209
- )
210
- finish_reason = response['choices'][0]['finish_reason']
211
- if finish_reason == 'length' or finish_reason == 'stop':
212
- translate = response['choices'][0]['message']['content']
213
- translated.append(translate)
214
- time.sleep(2)
215
- except openai.error.OpenAIError as e:
216
- print('server sibuk')
217
-
218
- for i in translated:
219
- @retry(openai.error.OpenAIError, tries=10, delay=10)
220
- openai.api_key = openai_key
221
- try:
222
- response = openai.ChatCompletion.create(
223
- model ="gpt-3.5-turbo",
224
- messages=[
225
- {"role": "system", "content": """You are a very professional article editor and perform SEO optimization on an article with utmost professionalism. berikut adalah SOP SEO yang harus kamu terapkan
226
- 1. meta decription max 160 characters
227
- 2. title max 60 characters
228
- 3. sentences max 20 words
229
- 4. paragraph max 300 words
230
- 5. sebisa mungkin focus keyword harus ada di title, bagian depan (sifatnya "sebisa mungkin". Kalau tidak bisa, di bagian manapun tidak masalah)
231
- 6. focus keyword harus ada di content
232
- 7. focus keyword harus ada di intro
233
- 8. focus keyword harus ada di meta desc
234
- 9. focus keyword harus ada di url
235
- 10. focus keyword harus ada di intro
236
- """},
237
- {"role": "user", "content": "Paraphrase the above article to make it a well-written and easily understandable piece for humans, following the conventions of renowned articles.The paraphrased result should be more than 2500 characters and less than 7000 characters. and then perform SEO optimization on the following article:\n" + i + "\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the reformatted article using this format: {reformatted article}"}
238
- ],
239
- temperature = 0
240
- )
241
- SEO = response['choices'][0]['message']['content']
242
- optimized.append(SEO)
243
  time.sleep(2)
244
- except openai.error.OpenAIError as e:
245
- print('server sibuk')
246
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  for i in optimized:
248
- @retry(openai.error.OpenAIError, tries=10, delay=10)
249
- openai.api_key = openai_key
250
- try:
251
- response = openai.ChatCompletion.create(
252
- model ="gpt-3.5-turbo",
253
- messages=[
254
- {"role": "system", "content": f"""
255
- You are a professional article writer and editor. I have an article that needs your editing expertise to align its writing style with specific instructions and guidelines:
256
- 1. Theme and Title: The blog article should have a clear and informative title that reflects the main topic.
257
- 2. Writing Style: The writing style in the blog article should appear serious, informative, and academic. It should use formal language to convey the importance of the discussed topic. Sentences should be long and rich in information.
258
- 3. Use of Data and Statistics: The blog article should support its arguments with concrete data and statistics.
259
- 4. Tone and Emotion: Despite the seriousness of the topic, the blog should not be overly emotional in its delivery. You should focus more on presenting facts and analysis rather than creating an emotional effect.
260
- 5. Subheadings: The use of subheadings should help readers follow the flow of the article and understand key points more easily.
261
- 6. Citations and Sources: The blog should cite reliable sources.
262
- 7. Graphics: The blog should use graphics to visualize data clearly.
263
- 8. SEO Keywords: Use keywords that will help the blog become more discoverable in search results.
264
- 9. Conclusion: The blog should also have a clear conclusion that summarizes the core findings of the study.
265
- 10. Final Thought: You should conclude the blog by providing readers with broader insights on the topic.
266
- 11. meta decription max 160 characters
267
- 12. title max 60 characters
268
- 13. sentences max 20 words
269
- 14. paragraph max 300 words
270
- 15. sebisa mungkin focus keyword harus ada di title, bagian depan (sifatnya "sebisa mungkin". Kalau tidak bisa, di bagian manapun tidak masalah)
271
- 16. focus keyword harus ada di content
272
- 17. focus keyword harus ada di intro
273
- 18. focus keyword harus ada di meta desccripton
274
- 19. focus keyword harus ada di url
275
- 20. focus keyword harus ada di intro
276
-
277
- Here is the article that you need to edit to adhere to these 20 criteria: {i}
278
- Please do not change the existing format in the article, just adjust the writing style according to the 10 criteria I mentioned.
279
- """ },
280
- {"role": "user", "content": "Please ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the rewrited article using this format: {rewrited article}"}
281
- ],
282
- temperature = 0
283
- )
284
- result = response['choices'][0]['message']['content']
285
- article.append(result)
286
- time.sleep(2)
287
- except openai.error.OpenAIError as e:
288
- print('server sibuk')
289
-
290
  for i in article:
291
- @retry(openai.error.OpenAIError, tries=10, delay=10)
292
- openai.api_key = openai_key
293
- try:
294
- response = openai.ChatCompletion.create(
295
- model ="gpt-3.5-turbo",
296
- messages=[
297
- {"role": "system", "content": "You are a professional article editor machine."},
298
- {"role": "user", "content": "Please rewrite the given article in the style of a professional writer for Forbes or The New York Times with bahasa indonesia as your native language:\n\n" + i + "\nAdd underline tags <u> and bold tags <b> to all foreign terms (non-Indonesian words) you encounter. You only have less than 7 attempts to do this, no more than that in order to keep the article neat and clean. \nThen, You must divide the article into several paragraphs, no less than 3 paragraphs. kamu juga harus membuat subheading menggunakan <h2> pada setiap sub topik pembahasan \n\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the reformatted article using this format:<h2>A brief headline of the article content</h2> <p>reformatted article</p>"}
299
- ],
300
- temperature = 0
301
- )
302
- font_formatted = response['choices'][0]['message']['content']
303
- edited_format.append(font_formatted)
304
- time.sleep(2)
305
- except openai.error.OpenAIError as e:
306
- print('server sibuk')
307
-
308
  for i in edited_format:
309
- try:
310
- openai.api_key = openai_key
311
- response = openai.ChatCompletion.create(
312
- model ="gpt-3.5-turbo",
313
- messages=[
314
- {"role": "system", "content": "You are a professional article editor machine."},
315
- {"role": "user", "content": "Please edit the given article:\n" + "\n" + i + f"\nAdd annotations to the words with the keywords {keyword} to format them as links in the HTML structure.the link should be connected to {backlink} \nThe format should be like this: <a title={keyword} href={backlink}>{keyword}</a>. YOU MUST Do this FORMAT ONLY for the first 3 keywords that appear and MUST be on different keywords, IF a keyword appears more than twice then simply ignored it by not adding any links to those keywords. Do not combine two keyword into one or modify any keyword. You only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean. \nExcept for the terms 'AI,' 'chatbot,' and 'omnichannel,' you are prohibited from providing backlinks. Additionally, you are not allowed to include backlinks to individuals' names or technology company names such as Google, Microsoft, and others. \nYou only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean.\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries."+"Provide only the reformatted article using this format: {new_formatted_article}"}
316
- ],
317
- temperature = 0
318
- )
319
- artikel_post = response['choices'][0]['message']['content']
320
- post_article.append(artikel_post)
321
- time.sleep(2)
322
- except openai.error.OpenAIError as e:
323
- print('server sibuk')
324
-
325
  meta_keywords = '<!-- wp:html –><meta name=”keywords” content=”chabot indonesia, chabot ai, bot master, artificial intelligence,ai, easy manage chatbot, bot ai,integration chatbot, chatbot online,ai chatbot, chatbot gpt, wizard gpt”><!-- /wp:html –->'
326
  post_article.append(meta_keywords)
327
  content = ''.join(post_article)
@@ -334,7 +289,6 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
334
 
335
  @retry(openai.error.OpenAIError, tries=10, delay=10)
336
  def generate_image_prompt(title):
337
- openai.api_key = openai_key
338
  try:
339
  response = openai.ChatCompletion.create(
340
  model="gpt-3.5-turbo", # engine = "deployment_name".
@@ -477,14 +431,15 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
477
  # selected_columns = result.loc[:, "Judul Artikel":"tags"]
478
  return result,image
479
 
480
-
481
  def scrap(link_scrap,backlink,keyword,openai_key,replicate_key):
 
482
  try:
483
- data,gambar= artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key)
484
  judul = data['Judul Artikel'][0]
485
  kontent = data["Konten Artikel"][0]
486
  return gambar,judul,kontent
487
- except:
488
  gambar = Image.open('error.png')
489
  judul = 'Gagal Generate Judul:Request Time Out'
490
  kontent = 'Gagal Generate Artikel:Request Time Out'
 
65
  article = []
66
  if len(artikel) > 1:
67
  for art in artikel:
68
+ response = openai.ChatCompletion.create(
69
+ model ="gpt-3.5-turbo",
70
+ messages=[
71
+ {"role": "system", "content": "You are a very professional article editor."},
72
+ {"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains. \nThen, you should also summarize the article so that it does not exceed 5000 characters" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned and summarized article's content}"}
73
+ ],
74
+ temperature = 0.1
75
+ )
76
+ finish_reason = response['choices'][0]['finish_reason']
77
+ if finish_reason == 'length' or finish_reason == 'stop':
78
+ result = response['choices'][0]['message']['content']
79
+ new_artikel.append(result)
 
 
 
 
 
80
  else:
81
+ for art in artikel:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  response = openai.ChatCompletion.create(
83
  model ="gpt-3.5-turbo",
84
  messages=[
85
+ {"role": "system", "content": "You are a very professional article editor."},
86
+ {"role": "user", "content": "I have a raw article that contains a lot of unnecessary data such as ads, website information, and article publishers, as well as links to other pages, and so on. Please clean up the article I provided so that only the article's content remains." + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {the cleaned article's content}"}
87
+ ],
88
  temperature = 0.1
89
  )
90
  finish_reason = response['choices'][0]['finish_reason']
91
  if finish_reason == 'length' or finish_reason == 'stop':
92
  result = response['choices'][0]['message']['content']
93
+ new_artikel.append(result)
 
 
94
 
95
+ new_art = [' '.join(new_artikel)]
96
+ for art in new_art:
 
 
 
97
  response = openai.ChatCompletion.create(
98
  model ="gpt-3.5-turbo",
99
  messages=[
100
+ {"role": "system", "content": "You are a very professional article editor and capable of generating compelling and professional article titles."},
101
+ {"role": "user", "content": "Paraphrase the above article to make it a well-written and easily understandable piece for humans, following the conventions of renowned articles. \nThen, You Must Generate a title that is appropriate for the article I provided. The title should be professional, similar to typical article titles and sound more natural for a human to read" + art + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: title:{title}, article: {new paraphrased article}"}
102
+ ],
103
+ temperature = 0.1
104
  )
105
+ finish_reason = response['choices'][0]['finish_reason']
106
+ if finish_reason == 'length' or finish_reason == 'stop':
107
+ result = response['choices'][0]['message']['content']
108
+ article.append(result)
109
+
110
+ content = article[0].split("\n")
111
+ title = content[0].replace('title:', '').replace("Title:", '').strip(
112
+ response = openai.ChatCompletion.create(
113
+ model ="gpt-3.5-turbo",
114
+ messages=[
115
+ {"role": "system", "content": "You are a professional translator and rewriter"},
116
+ {"role": "user", "content": "Please translate and rewrite this sentence into Indonesian language with the following requirements: \n1. The sentence should be concise, compact, and clear. \n2. The sentence length should not exceed 50 characters. \n3. The sentences should be professional, similar to typical article titles and sound more natural for a human to read.:" +title+"\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: Judul:{hasil rewrite}"}
117
+ ],
118
+ temperature = 0
119
+ )
120
+ judul = response['choices'][0]['message']['content']
121
  judul = judul.replace("Judul:", '').strip()
122
  judul = judul.replace("Title:", '').strip()
123
  try:
 
175
  post_article = []
176
 
177
  for i in artikel:
178
+ response = openai.ChatCompletion.create(
179
+ model ="gpt-3.5-turbo",
180
+ messages=[
181
+ {"role": "system", "content": "You are a proficient English to Indonesian language translator machine. You are capable of translating professionally according to the rules of the Indonesian language"},
182
+ {"role": "user", "content": "Translate the following article into Indonesian language. Then, you must resume the article translated. The translated result should be more than 2500 characters and less than 7000 characters.: " + i + "\nDo not write any explanation and any pleasantries. Please use the following complete format to display the output: {Professionally rewritten content}"}
183
+ ],
184
+ temperature = 0
185
+ )
186
+ finish_reason = response['choices'][0]['finish_reason']
187
+ if finish_reason == 'length' or finish_reason == 'stop':
188
+ translate = response['choices'][0]['message']['content']
189
+ translated.append(translate)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  time.sleep(2)
191
+
192
+ for i in translated:
193
+ response = openai.ChatCompletion.create(
194
+ model ="gpt-3.5-turbo",
195
+ messages=[
196
+ {"role": "system", "content": """You are a very professional article editor and perform SEO optimization on an article with utmost professionalism. berikut adalah SOP SEO yang harus kamu terapkan
197
+ 1. meta decription max 160 characters
198
+ 2. title max 60 characters
199
+ 3. sentences max 20 words
200
+ 4. paragraph max 300 words
201
+ 5. sebisa mungkin focus keyword harus ada di title, bagian depan (sifatnya "sebisa mungkin". Kalau tidak bisa, di bagian manapun tidak masalah)
202
+ 6. focus keyword harus ada di content
203
+ 7. focus keyword harus ada di intro
204
+ 8. focus keyword harus ada di meta desc
205
+ 9. focus keyword harus ada di url
206
+ 10. focus keyword harus ada di intro
207
+ """},
208
+ {"role": "user", "content": "Paraphrase the above article to make it a well-written and easily understandable piece for humans, following the conventions of renowned articles.The paraphrased result should be more than 2500 characters and less than 7000 characters. and then perform SEO optimization on the following article:\n" + i + "\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the reformatted article using this format: {reformatted article}"}
209
+ ],
210
+ temperature = 0
211
+ )
212
+ SEO = response['choices'][0]['message']['content']
213
+ optimized.append(SEO)
214
+ time.sleep(2)
215
+
216
  for i in optimized:
217
+ response = openai.ChatCompletion.create(
218
+ model ="gpt-3.5-turbo",
219
+ messages=[
220
+ {"role": "system", "content": f"""
221
+ You are a professional article writer and editor. I have an article that needs your editing expertise to align its writing style with specific instructions and guidelines:
222
+ 1. Theme and Title: The blog article should have a clear and informative title that reflects the main topic.
223
+ 2. Writing Style: The writing style in the blog article should appear serious, informative, and academic. It should use formal language to convey the importance of the discussed topic. Sentences should be long and rich in information.
224
+ 3. Use of Data and Statistics: The blog article should support its arguments with concrete data and statistics.
225
+ 4. Tone and Emotion: Despite the seriousness of the topic, the blog should not be overly emotional in its delivery. You should focus more on presenting facts and analysis rather than creating an emotional effect.
226
+ 5. Subheadings: The use of subheadings should help readers follow the flow of the article and understand key points more easily.
227
+ 6. Citations and Sources: The blog should cite reliable sources.
228
+ 7. Graphics: The blog should use graphics to visualize data clearly.
229
+ 8. SEO Keywords: Use keywords that will help the blog become more discoverable in search results.
230
+ 9. Conclusion: The blog should also have a clear conclusion that summarizes the core findings of the study.
231
+ 10. Final Thought: You should conclude the blog by providing readers with broader insights on the topic.
232
+ 11. meta decription max 160 characters
233
+ 12. title max 60 characters
234
+ 13. sentences max 20 words
235
+ 14. paragraph max 300 words
236
+ 15. sebisa mungkin focus keyword harus ada di title, bagian depan (sifatnya "sebisa mungkin". Kalau tidak bisa, di bagian manapun tidak masalah)
237
+ 16. focus keyword harus ada di content
238
+ 17. focus keyword harus ada di intro
239
+ 18. focus keyword harus ada di meta desccripton
240
+ 19. focus keyword harus ada di url
241
+ 20. focus keyword harus ada di intro
242
+
243
+ Here is the article that you need to edit to adhere to these 20 criteria: {i}
244
+ Please do not change the existing format in the article, just adjust the writing style according to the 10 criteria I mentioned.
245
+ """ },
246
+ {"role": "user", "content": "Please ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the rewrited article using this format: {rewrited article}"}
247
+ ],
248
+ temperature = 0
249
+ )
250
+ result = response['choices'][0]['message']['content']
251
+ article.append(result)
252
+ time.sleep(2)
253
+
 
 
 
 
 
254
  for i in article:
255
+ response = openai.ChatCompletion.create(
256
+ model ="gpt-3.5-turbo",
257
+ messages=[
258
+ {"role": "system", "content": "You are a professional article editor machine."},
259
+ {"role": "user", "content": "Please rewrite the given article in the style of a professional writer for Forbes or The New York Times with bahasa indonesia as your native language:\n\n" + i + "\nAdd underline tags <u> and bold tags <b> to all foreign terms (non-Indonesian words) you encounter. You only have less than 7 attempts to do this, no more than that in order to keep the article neat and clean. \nThen, You must divide the article into several paragraphs, no less than 3 paragraphs. kamu juga harus membuat subheading menggunakan <h2> pada setiap sub topik pembahasan \n\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries. Provide only the reformatted article using this format:<h2>A brief headline of the article content</h2> <p>reformatted article</p>"}
260
+ ],
261
+ temperature = 0
262
+ )
263
+ font_formatted = response['choices'][0]['message']['content']
264
+ edited_format.append(font_formatted)
265
+ time.sleep(2)
266
+
 
 
 
 
 
267
  for i in edited_format:
268
+ response = openai.ChatCompletion.create(
269
+ model ="gpt-3.5-turbo",
270
+ messages=[
271
+ {"role": "system", "content": "You are a professional article editor machine."},
272
+ {"role": "user", "content": "Please edit the given article:\n" + "\n" + i + f"\nAdd annotations to the words with the keywords {keyword} to format them as links in the HTML structure.the link should be connected to {backlink} \nThe format should be like this: <a title={keyword} href={backlink}>{keyword}</a>. YOU MUST Do this FORMAT ONLY for the first 3 keywords that appear and MUST be on different keywords, IF a keyword appears more than twice then simply ignored it by not adding any links to those keywords. Do not combine two keyword into one or modify any keyword. You only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean. \nExcept for the terms 'AI,' 'chatbot,' and 'omnichannel,' you are prohibited from providing backlinks. Additionally, you are not allowed to include backlinks to individuals' names or technology company names such as Google, Microsoft, and others. \nYou only have less than 3 attempts to do this, no more than that in order to keep the article neat and clean.\nPlease ensure the usage of proper and correct Indonesian language. \nDo not write any explanation and any pleasantries."+"Provide only the reformatted article using this format: {new_formatted_article}"}
273
+ ],
274
+ temperature = 0
275
+ )
276
+ artikel_post = response['choices'][0]['message']['content']
277
+ post_article.append(artikel_post)
278
+ time.sleep(2)
279
+
 
 
 
 
280
  meta_keywords = '<!-- wp:html –><meta name=”keywords” content=”chabot indonesia, chabot ai, bot master, artificial intelligence,ai, easy manage chatbot, bot ai,integration chatbot, chatbot online,ai chatbot, chatbot gpt, wizard gpt”><!-- /wp:html –->'
281
  post_article.append(meta_keywords)
282
  content = ''.join(post_article)
 
289
 
290
  @retry(openai.error.OpenAIError, tries=10, delay=10)
291
  def generate_image_prompt(title):
 
292
  try:
293
  response = openai.ChatCompletion.create(
294
  model="gpt-3.5-turbo", # engine = "deployment_name".
 
431
  # selected_columns = result.loc[:, "Judul Artikel":"tags"]
432
  return result,image
433
 
434
+ @retry(openai.error.OpenAIError, tries=10, delay=10)
435
  def scrap(link_scrap,backlink,keyword,openai_key,replicate_key):
436
+ openai.api_key = openai_key
437
  try:
438
+ data,gambar= artikel_processing(link_scrap,backlink,keyword,replicate_key)
439
  judul = data['Judul Artikel'][0]
440
  kontent = data["Konten Artikel"][0]
441
  return gambar,judul,kontent
442
+ except openai.error.OpenAIError as e:
443
  gambar = Image.open('error.png')
444
  judul = 'Gagal Generate Judul:Request Time Out'
445
  kontent = 'Gagal Generate Artikel:Request Time Out'