Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -433,37 +433,37 @@ def artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key):
|
|
| 433 |
return result,image
|
| 434 |
|
| 435 |
def scrap(link_scrap,backlink,keyword,openai_key,replicate_key):
|
| 436 |
-
try:
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
except:
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
|
| 468 |
def post(data,endpoint,endpoint_media,username,password,tags,categories,metode):
|
| 469 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|
|
|
|
| 433 |
return result,image
|
| 434 |
|
| 435 |
def scrap(link_scrap,backlink,keyword,openai_key,replicate_key):
|
| 436 |
+
# try:
|
| 437 |
+
data,gambar= artikel_processing(link_scrap,backlink,keyword,openai_key,replicate_key)
|
| 438 |
+
judul = data['Judul Artikel'][0]
|
| 439 |
+
kontent = data["Konten Artikel"][0]
|
| 440 |
+
desired_timezone = pytz.timezone('Asia/Jakarta')
|
| 441 |
+
current_time = datetime.datetime.now(desired_timezone)
|
| 442 |
+
Timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')
|
| 443 |
+
log = {
|
| 444 |
+
'Generated Title': judul,
|
| 445 |
+
'Timestamp': Timestamp
|
| 446 |
+
}
|
| 447 |
+
logs.append(log)
|
| 448 |
+
csv_data = StringIO()
|
| 449 |
+
csv_writer = csv.DictWriter(csv_data, fieldnames=logs[0].keys())
|
| 450 |
+
csv_writer.writeheader()
|
| 451 |
+
csv_writer.writerows(logs)
|
| 452 |
+
csv_bytes = csv_data.getvalue().encode('utf-8')
|
| 453 |
+
repo_name = get_full_repo_name(model_id="Article_Gen2", token="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")
|
| 454 |
+
file_url = upload_file(
|
| 455 |
+
path_or_fileobj=csv_bytes,
|
| 456 |
+
path_in_repo="logs.txt",
|
| 457 |
+
repo_id=repo_name,
|
| 458 |
+
repo_type="space",
|
| 459 |
+
token="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",
|
| 460 |
+
)
|
| 461 |
+
return gambar,judul,kontent
|
| 462 |
+
# except:
|
| 463 |
+
# gambar = Image.open('error.png')
|
| 464 |
+
# judul = 'Gagal Generate Judul:Request Time Out'
|
| 465 |
+
# kontent = 'Gagal Generate Artikel:Request Time Out'
|
| 466 |
+
# return gambar,judul,kontent
|
| 467 |
|
| 468 |
def post(data,endpoint,endpoint_media,username,password,tags,categories,metode):
|
| 469 |
credentials = base64.b64encode(f"{username}:{password}".encode("utf-8")).decode("utf-8")
|