Dede16 commited on
Commit
4defc29
·
1 Parent(s): a7f1ff3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -27,6 +27,7 @@ from huggingface_hub import (
27
  upload_file,
28
  )
29
  logs = []
 
30
 
31
  def split_article(article_text):
32
  words = article_text.split()
@@ -422,12 +423,10 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
422
  os.remove(tmp_path)
423
  except:
424
  image_data = None
 
425
  data = [{
426
  'Judul Artikel':judul,
427
- 'Konten Artikel':content,
428
- 'Image':image if 'image' in locals() else None,
429
- 'image_data':image_data
430
-
431
  }]
432
  result = pd.DataFrame(data)
433
  return result,image
@@ -465,19 +464,16 @@ def scrap(link_scrap,backlink,keyword,openai_key,replicate_key):
465
  # kontent = 'Gagal Generate Artikel:Request Time Out'
466
  # return gambar,judul,kontent
467
 
468
- def post(judul, kontent, gambar, endpoint,endpoint_media,username,password,tags,categories,metode):
469
  credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
470
  headers = {"Authorization": f"Basic {credentials}"}
471
 
472
- gambar_bytes = gambar.tobytes()
473
- gambar_base64 = base64.b64encode(gambar_bytes).decode('utf-8')
474
-
475
  data = {
476
  "alt_text": judul,
477
  "media_type": "image",
478
  "mime_type": "png"
479
  }
480
- files = {"file": ("image.jpg", gambar_base64)}
481
  try :
482
  response_media= requests.post(endpoint_media, headers=headers, data=data, files=files) # Send
483
 
@@ -527,6 +523,6 @@ with gr.Blocks(theme = "soft", title="Wordpress Article Generator") as article_g
527
  metode= gr.Radio(["publish", "draft"], label="Status Post", info="Pilih Metode Publish atau Draft Untuk Memposting")
528
  button_post = gr.Button("Post Article")
529
  status = gr.Textbox("", label="Response")
530
- button_post.click(fn=post, inputs=[outputs, content, img, endpoint,endpoint_media,username,password,tags,categories,metode], outputs=status)
531
  if __name__ == "__main__":
532
  article_generator.launch(share=False)
 
27
  upload_file,
28
  )
29
  logs = []
30
+ image_datas = []
31
 
32
  def split_article(article_text):
33
  words = article_text.split()
 
423
  os.remove(tmp_path)
424
  except:
425
  image_data = None
426
+ image_datas.append(image_data)
427
  data = [{
428
  'Judul Artikel':judul,
429
+ 'Konten Artikel':content
 
 
 
430
  }]
431
  result = pd.DataFrame(data)
432
  return result,image
 
464
  # kontent = 'Gagal Generate Artikel:Request Time Out'
465
  # return gambar,judul,kontent
466
 
467
+ def post(judul, kontent, endpoint,endpoint_media,username,password,tags,categories,metode):
468
  credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
469
  headers = {"Authorization": f"Basic {credentials}"}
470
 
 
 
 
471
  data = {
472
  "alt_text": judul,
473
  "media_type": "image",
474
  "mime_type": "png"
475
  }
476
+ files = {"file": ("image.jpg", image_datas[0])}
477
  try :
478
  response_media= requests.post(endpoint_media, headers=headers, data=data, files=files) # Send
479
 
 
523
  metode= gr.Radio(["publish", "draft"], label="Status Post", info="Pilih Metode Publish atau Draft Untuk Memposting")
524
  button_post = gr.Button("Post Article")
525
  status = gr.Textbox("", label="Response")
526
+ button_post.click(fn=post, inputs=[outputs, content, endpoint,endpoint_media,username,password,tags,categories,metode], outputs=status)
527
  if __name__ == "__main__":
528
  article_generator.launch(share=False)