Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -532,72 +532,72 @@ def artikel_processing(source_type,source,backlink,keyword,models,api_key,azure_
|
|
532 |
return None,None,None,None,None
|
533 |
|
534 |
def scrap(source_type,source,backlink,keyword,version,api_key,azure_api_base,replicate_key):
|
535 |
-
try:
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
|
545 |
-
with open("kontent.txt", "w") as file:
|
546 |
-
file.write(kontent)
|
547 |
|
548 |
repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
|
549 |
file_url = upload_file(
|
550 |
-
path_or_fileobj=
|
551 |
-
path_in_repo="
|
552 |
-
repo_id=repo_name,
|
553 |
-
repo_type="space",
|
554 |
-
token="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",
|
555 |
-
)
|
556 |
-
file_url = upload_file(
|
557 |
-
path_or_fileobj='judul.txt',
|
558 |
-
path_in_repo="judul.txt",
|
559 |
-
repo_id=repo_name,
|
560 |
-
repo_type="space",
|
561 |
-
token="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",
|
562 |
-
)
|
563 |
-
file_url = upload_file(
|
564 |
-
path_or_fileobj='kontent.txt',
|
565 |
-
path_in_repo="kontent.txt",
|
566 |
repo_id=repo_name,
|
567 |
repo_type="space",
|
568 |
token="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",
|
569 |
)
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
combined_data = existing_data + log
|
577 |
-
|
578 |
-
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
579 |
-
temp_file.write(combined_data)
|
580 |
-
|
581 |
-
|
582 |
-
repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
|
583 |
-
file_url = upload_file(
|
584 |
-
path_or_fileobj=temp_file.name,
|
585 |
-
path_in_repo="log_activity.txt",
|
586 |
-
repo_id=repo_name,
|
587 |
-
repo_type="space",
|
588 |
-
token="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",
|
589 |
-
)
|
590 |
-
status = "<h3>Berhasil Generate Artikel</h3>"
|
591 |
-
time.sleep(60)
|
592 |
-
return status,gambar
|
593 |
-
else:
|
594 |
-
status = "<h3>Gagal Generate Artikel, Coba Generate Ulang atau Ganti Input Source</h3>"
|
595 |
-
gambar = Image.open("error.png")
|
596 |
-
return status,gambar
|
597 |
-
except:
|
598 |
-
status = "<h3>Gagal Generate Artikel</h3>"
|
599 |
-
gambar = Image.open('error.png')
|
600 |
return status,gambar
|
|
|
|
|
|
|
|
|
601 |
|
602 |
def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
603 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
|
|
532 |
return None,None,None,None,None
|
533 |
|
534 |
def scrap(source_type,source,backlink,keyword,version,api_key,azure_api_base,replicate_key):
|
535 |
+
# try:
|
536 |
+
judul,kontent,gambar, image_data,url= artikel_processing(source_type,source,backlink,keyword,version,api_key,azure_api_base,replicate_key)
|
537 |
+
title = '<h1>'+judul+'</h1>'
|
538 |
+
desired_timezone = pytz.timezone('Asia/Jakarta')
|
539 |
+
current_time = datetime.datetime.now(desired_timezone)
|
540 |
+
Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
|
541 |
+
|
542 |
+
with open("judul.txt", "w") as file:
|
543 |
+
file.write(judul)
|
544 |
+
|
545 |
+
with open("kontent.txt", "w") as file:
|
546 |
+
file.write(kontent)
|
547 |
+
|
548 |
+
repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
|
549 |
+
file_url = upload_file(
|
550 |
+
path_or_fileobj=image_data,
|
551 |
+
path_in_repo="image_data.txt",
|
552 |
+
repo_id=repo_name,
|
553 |
+
repo_type="space",
|
554 |
+
token="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",
|
555 |
+
)
|
556 |
+
file_url = upload_file(
|
557 |
+
path_or_fileobj='judul.txt',
|
558 |
+
path_in_repo="judul.txt",
|
559 |
+
repo_id=repo_name,
|
560 |
+
repo_type="space",
|
561 |
+
token="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",
|
562 |
+
)
|
563 |
+
file_url = upload_file(
|
564 |
+
path_or_fileobj='kontent.txt',
|
565 |
+
path_in_repo="kontent.txt",
|
566 |
+
repo_id=repo_name,
|
567 |
+
repo_type="space",
|
568 |
+
token="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",
|
569 |
+
)
|
570 |
+
if kontent:
|
571 |
+
with open('log_activity.txt', 'r') as file:
|
572 |
+
existing_data = file.read()
|
573 |
+
|
574 |
+
log = url + "\n"
|
575 |
+
|
576 |
+
combined_data = existing_data + log
|
577 |
+
|
578 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
579 |
+
temp_file.write(combined_data)
|
580 |
|
|
|
|
|
581 |
|
582 |
repo_name = get_full_repo_name(model_id="Article_Gen4", token="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")
|
583 |
file_url = upload_file(
|
584 |
+
path_or_fileobj=temp_file.name,
|
585 |
+
path_in_repo="log_activity.txt",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
586 |
repo_id=repo_name,
|
587 |
repo_type="space",
|
588 |
token="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",
|
589 |
)
|
590 |
+
status = "<h3>Berhasil Generate Artikel</h3>"
|
591 |
+
time.sleep(60)
|
592 |
+
return status,gambar
|
593 |
+
else:
|
594 |
+
status = "<h3>Gagal Generate Artikel, Coba Generate Ulang atau Ganti Input Source</h3>"
|
595 |
+
gambar = Image.open("error.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
return status,gambar
|
597 |
+
# except:
|
598 |
+
# status = "<h3>Gagal Generate Artikel</h3>"
|
599 |
+
# gambar = Image.open('error.png')
|
600 |
+
# return status,gambar
|
601 |
|
602 |
def post(endpoint,endpoint_media,username,password,tags,categories,metode):
|
603 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|