Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -405,7 +405,6 @@ def get_image(prompt):
|
|
405 |
"width": 1648,
|
406 |
"height": 1024}
|
407 |
)
|
408 |
-
prediction
|
409 |
prediction.reload()
|
410 |
prediction.wait()
|
411 |
|
@@ -413,21 +412,32 @@ def get_image(prompt):
|
|
413 |
print(f"Error: {prediction.error}")
|
414 |
print(f"Last Log")
|
415 |
print(prediction.logs)
|
416 |
-
|
|
|
417 |
response = requests.get(prediction.output[0])
|
418 |
-
image_base64 = base64.b64encode(response.content)
|
419 |
-
|
420 |
-
image = image.crop((3, 0, 1645, 1024))
|
421 |
-
w, h = image.size
|
422 |
-
new_w = int(w / 1.641)
|
423 |
-
new_h = int(h / 1.641)
|
424 |
-
image = image.resize((new_w, new_h), Image.ANTIALIAS)
|
425 |
-
image_data = base64.b64encode(image.tobytes()).decode('utf-8')
|
426 |
-
return image_data, image
|
427 |
except Exception as e:
|
428 |
print(f"An error occurred: {e}")
|
429 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
430 |
|
|
|
|
|
431 |
|
432 |
# return tags, content, url #image, image_data
|
433 |
|
@@ -437,21 +447,21 @@ def get_image(prompt):
|
|
437 |
# return judul, content
|
438 |
|
439 |
|
440 |
-
with gr.Blocks(theme = "soft", title="Article Writer") as article_generator:
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
if __name__ == "__main__":
|
457 |
-
|
|
|
405 |
"width": 1648,
|
406 |
"height": 1024}
|
407 |
)
|
|
|
408 |
prediction.reload()
|
409 |
prediction.wait()
|
410 |
|
|
|
412 |
print(f"Error: {prediction.error}")
|
413 |
print(f"Last Log")
|
414 |
print(prediction.logs)
|
415 |
+
return None
|
416 |
+
elif (prediction.status == 'succeeded' and prediction.output is not None):
|
417 |
response = requests.get(prediction.output[0])
|
418 |
+
image_base64 = base64.b64encode(response.content).decode('utf-8')
|
419 |
+
return image_base64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
except Exception as e:
|
421 |
print(f"An error occurred: {e}")
|
422 |
return None
|
423 |
+
|
424 |
+
def show_image(image_data, width=800, height=600):
|
425 |
+
# Konversi data gambar base64 menjadi gambar PIL
|
426 |
+
image_bytes = base64.b64decode(image_data)
|
427 |
+
image = Image.open(io.BytesIO(image_bytes))
|
428 |
+
|
429 |
+
# Resize gambar sesuai dengan lebar dan tinggi yang diinginkan
|
430 |
+
image = image.resize((width, height), Image.ANTIALIAS)
|
431 |
+
|
432 |
+
# Konversi kembali gambar ke format base64
|
433 |
+
buffered = io.BytesIO()
|
434 |
+
image.save(buffered, format="JPEG")
|
435 |
+
image_data_resized = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
436 |
+
|
437 |
+
return gr.outputs.Image(image_data_resized)
|
438 |
|
439 |
+
iface = gr.Interface(fn=get_image, inputs="text", outputs=show_image)
|
440 |
+
iface.launch()
|
441 |
|
442 |
# return tags, content, url #image, image_data
|
443 |
|
|
|
447 |
# return judul, content
|
448 |
|
449 |
|
450 |
+
# with gr.Blocks(theme = "soft", title="Article Writer") as article_generator:
|
451 |
+
# gr.Markdown(
|
452 |
+
# """
|
453 |
+
# # Article Writer
|
454 |
+
# Buat artikel yang anda inginkan dengan mudah, cukup menuliskan keyword atau topik artikel yang ingin anda buat dan dalam sekejap artikel tersebut menjadi milik anda.
|
455 |
+
# """)
|
456 |
+
# with gr.Row():
|
457 |
+
# inputs = gr.Textbox(placeholder="Link Article", show_label=False)
|
458 |
+
# with gr.Row():
|
459 |
+
# button_scrap = gr.Button("Scrap Article")
|
460 |
+
# with gr.Row():
|
461 |
+
# # title = gr.Textbox("", label="Title")
|
462 |
+
# # content = gr.Textbox("", label="Content")
|
463 |
+
# img_data = gr.Textbox("", label="Content")
|
464 |
+
# img = gr.Image("", label="Image")
|
465 |
+
# button_scrap.click(fn=get_image, inputs=inputs, outputs=[img, img_data])
|
466 |
+
# if __name__ == "__main__":
|
467 |
+
# article_generator.launch(share=False)
|