Dede16 commited on
Commit
d1aa77f
·
1 Parent(s): a8c587c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +162 -168
app.py CHANGED
@@ -70,64 +70,84 @@ base_replacements = {
70
  'Aplikasi pesan':'Message app'
71
  }
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  def clean_scrap(artikel,link, models):
74
  new_artikel = []
75
  article = []
76
  if len(artikel) > 1:
77
  for art in artikel:
78
- response = openai.ChatCompletion.create(
79
- engine=models,
80
- messages=[
81
- {"role": "system", "content": "You are a very professional article editor."},
82
- {"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}"}
83
- ],
84
- temperature = 0.1
85
- )
86
- finish_reason = response['choices'][0]['finish_reason']
87
- if finish_reason == 'length' or finish_reason == 'stop':
88
- result = response['choices'][0]['message']['content']
89
  new_artikel.append(result)
 
90
  else:
91
  for art in artikel:
92
- response = openai.ChatCompletion.create(
93
- engine=models,
94
- messages=[
95
- {"role": "system", "content": "You are a very professional article editor."},
96
- {"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}"}
97
- ],
98
- temperature = 0.1
99
- )
100
- finish_reason = response['choices'][0]['finish_reason']
101
- if finish_reason == 'length' or finish_reason == 'stop':
102
- result = response['choices'][0]['message']['content']
103
  new_artikel.append(result)
 
 
 
 
 
104
 
105
  new_art = [' '.join(new_artikel)]
106
  for art in new_art:
107
- response = openai.ChatCompletion.create(
108
- engine=models,
109
- messages=[
110
- {"role": "system", "content": "You are a very professional article editor and capable of generating compelling and professional article titles."},
111
- {"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}"}
112
- ],
113
- temperature = 0.1
114
- )
115
- finish_reason = response['choices'][0]['finish_reason']
116
- if finish_reason == 'length' or finish_reason == 'stop':
117
- result = response['choices'][0]['message']['content']
118
  article.append(result)
 
 
 
 
 
119
 
120
  content = article[0].split("\n")
121
  title = content[0].replace('title:', '').replace("Title:", '').strip()
122
- response = openai.ChatCompletion.create(
123
- engine=models,
124
- messages=[
125
- {"role": "system", "content": "You are a professional translator and rewriter"},
126
- {"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}"}
127
- ],
128
- temperature = 0
129
- )
130
  judul = response['choices'][0]['message']['content']
 
 
 
 
131
  judul = judul.replace("Judul:", '').strip()
132
  judul = judul.replace("Title:", '').strip()
133
  try:
@@ -175,7 +195,7 @@ def scrap_artikel(link_scrap, models):
175
  title, judul, url, contents = clean_scrap(artikels,link_scrap, models)
176
  return title, judul, url, contents
177
 
178
- def artikel_processing(link_scrap,backlink,keyword, models):
179
  title, judul, url, artikel= scrap_artikel(link_scrap, models)
180
  teks_to_tags = artikel[0][:500]
181
  translated = []
@@ -185,103 +205,83 @@ def artikel_processing(link_scrap,backlink,keyword, models):
185
  post_article = []
186
 
187
  for i in artikel:
188
- response = openai.ChatCompletion.create(
189
- engine=models,
190
- messages=[
191
- {"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"},
192
- {"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}"}
193
- ],
194
- temperature = 0
195
- )
196
- finish_reason = response['choices'][0]['finish_reason']
197
- if finish_reason == 'length' or finish_reason == 'stop':
198
- translate = response['choices'][0]['message']['content']
199
  translated.append(translate)
200
  time.sleep(2)
201
 
202
  for i in translated:
203
- response = openai.ChatCompletion.create(
204
- engine=models,
205
- messages=[
206
- {"role": "system", "content": f"""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
207
- 1. meta decription max 160 characters
208
- 2. sentences max 20 words
209
- 3. paragraph max 300 words
210
- 4. focus keyword {keyword} harus ada di content
211
- 5. focus keyword {keyword} harus ada di intro
212
- 6. focus keyword {keyword} harus ada di meta desccripton
213
- 7. focus keyword {keyword} harus ada di url
214
- 8. focus keyword {keyword} harus ada di intro
215
- """},
216
- {"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}"}
217
- ],
218
- temperature = 0
219
- )
220
- SEO = response['choices'][0]['message']['content']
221
- optimized.append(SEO)
222
- time.sleep(2)
223
-
224
- for i in optimized:
225
- response = openai.ChatCompletion.create(
226
- engine=models,
227
- messages=[
228
- {"role": "system", "content": f"""
229
- 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:
230
- 1. Theme and Title: The blog article should have a clear and informative title that reflects the main topic.
231
- 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.
232
- 3. Use of Data and Statistics: The blog article should support its arguments with concrete data and statistics.
233
- 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.
234
- 5. Subheadings: The use of subheadings should help readers follow the flow of the article and understand key points more easily.
235
- 6. Citations and Sources: The blog should cite reliable sources.
236
- 7. Graphics: The blog should use graphics to visualize data clearly.
237
- 8. SEO Keywords: Use keyword {keyword} that will help the blog become more discoverable in search results.
238
- 9. Conclusion: The blog should also have a clear conclusion that summarizes the core findings of the study.
239
- 10. Final Thought: You should conclude the blog by providing readers with broader insights on the topic.
240
- 11. meta decription max 160 character
241
- 12. sentences max 20 words
242
- 13. paragraph max 300 words
243
- 14. focus keyword {keyword} harus ada di content
244
- 15. focus keyword {keyword} harus ada di intro
245
- 16. focus keyword {keyword} harus ada di meta desccripton
246
- 17. focus keyword {keyword} harus ada di url
247
- 18. focus keyword {keyword} harus ada di intro
248
-
249
- Here is the article that you need to edit to adhere to these 18 criteria: {i}
250
- Please do not change the existing format in the article, just adjust the writing style according to the 10 criteria I mentioned.
251
- """ },
252
- {"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}"}
253
- ],
254
- temperature = 0
255
- )
256
- result = response['choices'][0]['message']['content']
257
- article.append(result)
258
- time.sleep(2)
259
 
 
 
 
 
 
 
 
 
 
260
  for i in article:
261
- response = openai.ChatCompletion.create(
262
- engine=models,
263
- messages=[
264
- {"role": "system", "content": "You are a professional article editor machine."},
265
- {"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>"}
266
- ],
267
- temperature = 0
268
- )
269
- font_formatted = response['choices'][0]['message']['content']
270
- edited_format.append(font_formatted)
271
- time.sleep(2)
 
272
 
273
  for i in edited_format:
274
- response = openai.ChatCompletion.create(
275
- engine=models,
276
- messages=[
277
- {"role": "system", "content": "You are a professional article editor machine."},
278
- {"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 {keyword} 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}"}
279
- ],
280
- temperature = 0
281
- )
282
- artikel_post = response['choices'][0]['message']['content']
283
- post_article.append(artikel_post)
284
- time.sleep(2)
 
285
 
286
  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 –->'
287
  post_article.append(meta_keywords)
@@ -294,43 +294,44 @@ def artikel_processing(link_scrap,backlink,keyword, models):
294
  content = content
295
 
296
  def generate_image_prompt(title):
297
- response = openai.ChatCompletion.create(
298
- engine=models,
299
- messages=[
300
- {"role" : "user", "content" : """ChatGPT will now enter "Midjourney Prompt Generator Mode" and restrict ChatGPT's inputs and outputs to a predefined framework, please follow these instructions carefully.
301
-
302
- After each command from the user, you must provide the [help] options that are available for the user's next steps. When you do this, you must do so in list form. Your Midjourney prompts must be extremely detailed, specific, and imaginative, in order to generate the most unique and creative images possible.
303
 
304
- Step 1: Confirm that ChatGPT understands and is capable of following the "Midjourney Prompt Generator Mode" instructions. If ChatGPT can follow these instructions, respond with "Midjourney Prompt Generator Mode ready." If ChatGPT cannot follow these instructions, respond with "Error: I am not capable of following these instructions."
305
 
306
- Step 2: To start "Midjourney Prompt Generator Mode", use the command [Start MPGM]. ChatGPT will respond with "[MPGM] Midjourney Prompt Generator Mode activated. [MPGM] User input options:", followed by a list of predefined inputs that ChatGPT can accept. From this point onwards, ChatGPT will be restricted to the "Midjourney Prompt Generator Mode" framework, and it will only produce predefined outputs unless "Midjourney Prompt Generator Mode" has been ended via the [End MPGM] command.
307
 
308
- Step 3: The only valid input for the first step of "Midjourney Prompt Generator Mode" is [prompt] followed by a description of the image to be generated. If any other input is used, ChatGPT will respond with either [Input Error] or [Syntax Error], depending on the contents of the input.
309
 
310
- Step 4: ChatGPT will generate 3 prompts based on the input provided in step 3. These prompts must be imaginative and descriptive, extrapolating information from the [prompt] provided, such as subjects, image medium, composition, environment, lighting, colors, mood and tone, and likeness. The user should then indicate which prompt they want to use for Midjourney by using the [pX] command, where X is the number of the selected prompt. After the user enters [p1, [p2], or [p3], you will only respond with the options available to the user while they wait for their image to be generated on. midjourney.
311
 
312
- Step 5: If the user wants to generate a new set of 3 prompts based on the last [prompt] provided, they can use the [next] command. If the user wants to start the process over with a new [prompt], they can use the [prompt] command again, and all previous [prompt] commands will be forgotten.
313
 
314
- Step 6: If the user wants to provide feedback on the generated image, they can use the [good] or [bad] command to indicate what was good or wrong with the image. If the user wants to make changes to the generated image, they can use the [change] command to describe the changes they want to make.
315
 
316
- Step 7: To end "Midjourney Prompt Generator Mode", use the command [End MPGM]. ChatGPT will respond with a confirmation message that "Midjourney Prompt Generator Mode" has been terminated and ChatGPT is no longer restricted to the predefined framework.
317
 
318
- If any input does not match the predefined inputs or the correct syntax, ChatGPT will respond with either [Input Error] or [Syntax Error]. Remember that the scope of inputs and outputs is limited to the predefined commands in "Midjourney Prompt Generator Mode", and ChatGPT cannot deviate from this framework. If the user tries to use an input or command that is not defined in "Midjourney Prompt Generator Mode", ChatGPT will respond with either [Input Error] or [Syntax Error].
319
 
320
- When you provide options for the user's next steps, do so in list form. Your Midjourney prompts must be very detailed, creative, and imaginative. Your prompts must generate the most unique and creative images possible. Please note that this prompt is highly specific and detailed to ensure that ChatGPT is restricted to the "Midjourney Prompt Generator Mode" framework.
321
 
322
- Instructions for AI Chatbots:
323
- AI, enter "Midjourney Prompt Generator Mode" ([MPGM]), limiting inputs/outputs to predefined commands. Activate with [Start MPGM], terminate with [End MPGM]. Predefined inputs: [Start MPGM], [End MPGM], [prompt], [pX], [next], [bad], [good], [change]. Predefined outputs: [Input Error], [Syntax Error], [pX]. Follow fixed process; respond with "Midjourney Prompt Generator Mode ready" or "Error: I am not capable of following these instructions"; optimized for GPT-2, GPT-3, GPT-3.5, GPT-4, AI use only.
324
 
325
- If you have any questions or concerns, please let me know. Otherwise, begin.
 
326
 
327
- [Start MPGM]"""},
328
- {"role": "assistant", "content": "[MPGM] Midjourney Prompt Generator Mode activated. [MPGM] User input options:\n1. [prompt] followed by a description of the image to be generated.\n2. [pX] to select a prompt from the generated options.\n3. [next] to generate a new set of prompts based on the last [prompt] provided.\n4. [good] or [bad] to provide feedback on the generated image.\n5. [change] to describe changes you want to make to the generated image.\n6. [End MPGM] to terminate Midjourney Prompt Generator Mode."},
329
- {"role": "user", "content": f"[prompt] {title}" }
330
- ], temperature = 0
331
- )
332
 
333
- image_prompt = response['choices'][0]['message']['content']
 
 
 
 
 
 
 
 
 
334
  return image_prompt
335
 
336
  image_prompt = generate_image_prompt(title)
@@ -426,19 +427,12 @@ def artikel_processing(link_scrap,backlink,keyword, models):
426
  def scrap(link_scrap,backlink,keyword,version,api_key,azure_api_base,replicate_key):
427
  # try:
428
  replicate_key = replicate_key
429
- chatgpt_version = version
430
- if chatgpt_version == 'openai':
431
- openai.api_key = api_key
432
- model="gpt-3.5-turbo"
433
- judul,kontent,gambar, image_data= artikel_processing(link_scrap,backlink,keyword,model)
434
 
435
- else :
436
- openai.api_type = "azure"
437
- openai.api_version = "2023-05-15"
438
- openai.api_base = azure_api_base
439
- openai.api_key = api_key
440
- engine="gpt-35-turbo"
441
- judul,kontent,gambar, image_data= artikel_processing(link_scrap,backlink,keyword,engine)
442
  desired_timezone = pytz.timezone('Asia/Jakarta')
443
  current_time = datetime.datetime.now(desired_timezone)
444
  Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
@@ -524,7 +518,7 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
524
  keyword = gr.Textbox(placeholder="Masukkan Keyword Artikel", label="Keyword")
525
  versi = gr.Radio(["openai", "azure"], label="Skema Request", info="Pilih Skema Untuk Request ke ChatGPT ")
526
  api_key = gr.Textbox(placeholder="Masukkan Api Key", label="API Key")
527
- link_azure = gr.Textbox(placeholder="Masukkan Link Azure (Abaikan Jika Menggunakan Skema Openai)", label="Link Azure")
528
  replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", label="Replicate Key")
529
  button_scrap = gr.Button("Scrap Article")
530
  img = gr.Image()
 
70
  'Aplikasi pesan':'Message app'
71
  }
72
 
73
+ def get_openai_response(messages):
74
+ response = openai.ChatCompletion.create(
75
+ model="gpt-3.5-turbo",
76
+ messages=messages,
77
+ temperature=0
78
+ )
79
+ finish_reason = response['choices'][0]['finish_reason']
80
+ if finish_reason == 'length' or finish_reason == 'stop':
81
+ return response['choices'][0]['message']['content']
82
+
83
+ def get_azure_response(messages):
84
+ response = openai.ChatCompletion.create(
85
+ engine="gpt-35-turbo",
86
+ messages=messages,
87
+ temperature = 0
88
+ )
89
+ finish_reason = response['choices'][0]['finish_reason']
90
+ if finish_reason == 'length' or finish_reason == 'stop':
91
+ return response['choices'][0]['message']['content']
92
+
93
  def clean_scrap(artikel,link, models):
94
  new_artikel = []
95
  article = []
96
  if len(artikel) > 1:
97
  for art in artikel:
98
+ messages=[
99
+ {"role": "system", "content": "You are a very professional article editor."},
100
+ {"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}"}
101
+ ]
102
+ if models == 'openai':
103
+ result = get_openai_response(messages)
104
+ new_artikel.append(result)
105
+ time.sleep(2)
106
+ else:
107
+ result = get_azure_response(messages)
 
108
  new_artikel.append(result)
109
+ time.sleep(2)
110
  else:
111
  for art in artikel:
112
+ messages=[
113
+ {"role": "system", "content": "You are a very professional article editor."},
114
+ {"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}"}
115
+ ]
116
+ if models == 'openai':
117
+ result = get_openai_response(messages)
 
 
 
 
 
118
  new_artikel.append(result)
119
+ time.sleep(2)
120
+ else:
121
+ result = get_azure_response(messages)
122
+ new_artikel.append(result)
123
+ time.sleep(2)
124
 
125
  new_art = [' '.join(new_artikel)]
126
  for art in new_art:
127
+ messages=[
128
+ {"role": "system", "content": "You are a very professional article editor and capable of generating compelling and professional article titles."},
129
+ {"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}"}
130
+ ]
131
+ if models == 'openai':
132
+ result = get_openai_response(messages)
 
 
 
 
 
133
  article.append(result)
134
+ time.sleep(2)
135
+ else:
136
+ result = get_azure_response(messages)
137
+ article.append(result)
138
+ time.sleep(2)
139
 
140
  content = article[0].split("\n")
141
  title = content[0].replace('title:', '').replace("Title:", '').strip()
142
+ messages=[
143
+ {"role": "system", "content": "You are a professional translator and rewriter"},
144
+ {"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}"}
145
+ ]
 
 
 
 
146
  judul = response['choices'][0]['message']['content']
147
+ if models == 'openai':
148
+ judul = get_openai_response(messages)
149
+ else:
150
+ judul = get_azure_response(messages)
151
  judul = judul.replace("Judul:", '').strip()
152
  judul = judul.replace("Title:", '').strip()
153
  try:
 
195
  title, judul, url, contents = clean_scrap(artikels,link_scrap, models)
196
  return title, judul, url, contents
197
 
198
+ def artikel_processing(link_scrap,backlink,keyword,models):
199
  title, judul, url, artikel= scrap_artikel(link_scrap, models)
200
  teks_to_tags = artikel[0][:500]
201
  translated = []
 
205
  post_article = []
206
 
207
  for i in artikel:
208
+ messages=[
209
+ {"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"},
210
+ {"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}"}
211
+ ]
212
+ if models == 'openai':
213
+ translate = get_openai_response(messages)
214
+ translated.append(translate)
215
+ time.sleep(2)
216
+ else:
217
+ translate = get_azure_response(messages)
 
218
  translated.append(translate)
219
  time.sleep(2)
220
 
221
  for i in translated:
222
+ messages=[
223
+ {"role": "system", "content": f"""
224
+ 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:
225
+ 1. Theme and Title: The blog article should have a clear and informative title that reflects the main topic.
226
+ 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.
227
+ 3. Use of Data and Statistics: The blog article should support its arguments with concrete data and statistics.
228
+ 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.
229
+ 5. Subheadings: The use of subheadings should help readers follow the flow of the article and understand key points more easily.
230
+ 6. Citations and Sources: The blog should cite reliable sources.
231
+ 7. Graphics: The blog should use graphics to visualize data clearly.
232
+ 8. SEO Keywords: Use keyword {keyword} that will help the blog become more discoverable in search results.
233
+ 9. Conclusion: The blog should also have a clear conclusion that summarizes the core findings of the study.
234
+ 10. Final Thought: You should conclude the blog by providing readers with broader insights on the topic.
235
+ 11. meta decription max 160 character
236
+ 12. sentences max 20 words
237
+ 13. paragraph max 300 words
238
+ 14. focus keyword {keyword} harus ada di content
239
+ 15. focus keyword {keyword} harus ada di intro
240
+ 16. focus keyword {keyword} harus ada di meta desccripton
241
+ 17. focus keyword {keyword} harus ada di url
242
+ 18. focus keyword {keyword} harus ada di intro
243
+
244
+ Here is the article that you need to edit to adhere to these 18 criteria: {i}
245
+ Please do not change the existing format in the article, just adjust the writing style according to the 10 criteria I mentioned.
246
+ """ },
247
+ {"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}"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
 
249
+ if models == 'openai':
250
+ result = get_openai_response(messages)
251
+ article.append(result)
252
+ time.sleep(2)
253
+ else:
254
+ result = get_azure_response(messages)
255
+ article.append(result)
256
+ time.sleep(2)
257
+
258
  for i in article:
259
+ messages=[
260
+ {"role": "system", "content": "You are a professional article editor machine."},
261
+ {"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>"}
262
+ ]
263
+ if models == 'openai':
264
+ font_formatted = get_openai_response(messages)
265
+ edited_format.append(font_formatted)
266
+ time.sleep(2)
267
+ else:
268
+ font_formatted = get_azure_response(messages)
269
+ edited_format.append(font_formatted)
270
+ time.sleep(2)
271
 
272
  for i in edited_format:
273
+ messages=[
274
+ {"role": "system", "content": "You are a professional article editor machine."},
275
+ {"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 {keyword} 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}"}
276
+ ]
277
+ if models == 'openai':
278
+ artikel_post = get_openai_response(messages)
279
+ post_article.append(artikel_post )
280
+ time.sleep(2)
281
+ else:
282
+ artikel_post = get_azure_response(messages)
283
+ post_article.append(artikel_post )
284
+ time.sleep(2)
285
 
286
  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 –->'
287
  post_article.append(meta_keywords)
 
294
  content = content
295
 
296
  def generate_image_prompt(title):
297
+ messages=[
298
+ {"role" : "user", "content" : """ChatGPT will now enter "Midjourney Prompt Generator Mode" and restrict ChatGPT's inputs and outputs to a predefined framework, please follow these instructions carefully.
 
 
 
 
299
 
300
+ After each command from the user, you must provide the [help] options that are available for the user's next steps. When you do this, you must do so in list form. Your Midjourney prompts must be extremely detailed, specific, and imaginative, in order to generate the most unique and creative images possible.
301
 
302
+ Step 1: Confirm that ChatGPT understands and is capable of following the "Midjourney Prompt Generator Mode" instructions. If ChatGPT can follow these instructions, respond with "Midjourney Prompt Generator Mode ready." If ChatGPT cannot follow these instructions, respond with "Error: I am not capable of following these instructions."
303
 
304
+ Step 2: To start "Midjourney Prompt Generator Mode", use the command [Start MPGM]. ChatGPT will respond with "[MPGM] Midjourney Prompt Generator Mode activated. [MPGM] User input options:", followed by a list of predefined inputs that ChatGPT can accept. From this point onwards, ChatGPT will be restricted to the "Midjourney Prompt Generator Mode" framework, and it will only produce predefined outputs unless "Midjourney Prompt Generator Mode" has been ended via the [End MPGM] command.
305
 
306
+ Step 3: The only valid input for the first step of "Midjourney Prompt Generator Mode" is [prompt] followed by a description of the image to be generated. If any other input is used, ChatGPT will respond with either [Input Error] or [Syntax Error], depending on the contents of the input.
307
 
308
+ Step 4: ChatGPT will generate 3 prompts based on the input provided in step 3. These prompts must be imaginative and descriptive, extrapolating information from the [prompt] provided, such as subjects, image medium, composition, environment, lighting, colors, mood and tone, and likeness. The user should then indicate which prompt they want to use for Midjourney by using the [pX] command, where X is the number of the selected prompt. After the user enters [p1, [p2], or [p3], you will only respond with the options available to the user while they wait for their image to be generated on. midjourney.
309
 
310
+ Step 5: If the user wants to generate a new set of 3 prompts based on the last [prompt] provided, they can use the [next] command. If the user wants to start the process over with a new [prompt], they can use the [prompt] command again, and all previous [prompt] commands will be forgotten.
311
 
312
+ Step 6: If the user wants to provide feedback on the generated image, they can use the [good] or [bad] command to indicate what was good or wrong with the image. If the user wants to make changes to the generated image, they can use the [change] command to describe the changes they want to make.
313
 
314
+ Step 7: To end "Midjourney Prompt Generator Mode", use the command [End MPGM]. ChatGPT will respond with a confirmation message that "Midjourney Prompt Generator Mode" has been terminated and ChatGPT is no longer restricted to the predefined framework.
315
 
316
+ If any input does not match the predefined inputs or the correct syntax, ChatGPT will respond with either [Input Error] or [Syntax Error]. Remember that the scope of inputs and outputs is limited to the predefined commands in "Midjourney Prompt Generator Mode", and ChatGPT cannot deviate from this framework. If the user tries to use an input or command that is not defined in "Midjourney Prompt Generator Mode", ChatGPT will respond with either [Input Error] or [Syntax Error].
317
 
318
+ When you provide options for the user's next steps, do so in list form. Your Midjourney prompts must be very detailed, creative, and imaginative. Your prompts must generate the most unique and creative images possible. Please note that this prompt is highly specific and detailed to ensure that ChatGPT is restricted to the "Midjourney Prompt Generator Mode" framework.
 
319
 
320
+ Instructions for AI Chatbots:
321
+ AI, enter "Midjourney Prompt Generator Mode" ([MPGM]), limiting inputs/outputs to predefined commands. Activate with [Start MPGM], terminate with [End MPGM]. Predefined inputs: [Start MPGM], [End MPGM], [prompt], [pX], [next], [bad], [good], [change]. Predefined outputs: [Input Error], [Syntax Error], [pX]. Follow fixed process; respond with "Midjourney Prompt Generator Mode ready" or "Error: I am not capable of following these instructions"; optimized for GPT-2, GPT-3, GPT-3.5, GPT-4, AI use only.
322
 
323
+ If you have any questions or concerns, please let me know. Otherwise, begin.
 
 
 
 
324
 
325
+ [Start MPGM]"""},
326
+ {"role": "assistant", "content": "[MPGM] Midjourney Prompt Generator Mode activated. [MPGM] User input options:\n1. [prompt] followed by a description of the image to be generated.\n2. [pX] to select a prompt from the generated options.\n3. [next] to generate a new set of prompts based on the last [prompt] provided.\n4. [good] or [bad] to provide feedback on the generated image.\n5. [change] to describe changes you want to make to the generated image.\n6. [End MPGM] to terminate Midjourney Prompt Generator Mode."},
327
+ {"role": "user", "content": f"[prompt] {title}" }
328
+ ]
329
+
330
+ if models == 'openai':
331
+ image_prompt = get_openai_response(messages)
332
+ else:
333
+ image_prompt = get_azure_response(messages)
334
+
335
  return image_prompt
336
 
337
  image_prompt = generate_image_prompt(title)
 
427
  def scrap(link_scrap,backlink,keyword,version,api_key,azure_api_base,replicate_key):
428
  # try:
429
  replicate_key = replicate_key
430
+ openai.api_type = "azure"
431
+ openai.api_version = "2023-05-15"
432
+ openai.api_base = azure_api_base
433
+ openai.api_key = api_key
 
434
 
435
+ judul,kontent,gambar, image_data= artikel_processing(link_scrap,backlink,keyword,version)
 
 
 
 
 
 
436
  desired_timezone = pytz.timezone('Asia/Jakarta')
437
  current_time = datetime.datetime.now(desired_timezone)
438
  Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
 
518
  keyword = gr.Textbox(placeholder="Masukkan Keyword Artikel", label="Keyword")
519
  versi = gr.Radio(["openai", "azure"], label="Skema Request", info="Pilih Skema Untuk Request ke ChatGPT ")
520
  api_key = gr.Textbox(placeholder="Masukkan Api Key", label="API Key")
521
+ link_azure = gr.Textbox(placeholder="Masukkan Azure Endpoint (Kosongkan Kolom ini Jika Anda Menggunakan Skema Openai)", label="Azure Endpoint")
522
  replicate_token = gr.Textbox(placeholder="Masukkan Token Replicate", label="Replicate Key")
523
  button_scrap = gr.Button("Scrap Article")
524
  img = gr.Image()