Dede16 commited on
Commit
a8618ef
·
1 Parent(s): b0348ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -46
app.py CHANGED
@@ -400,11 +400,12 @@ def get_image(prompt):
400
  sdxl_version = sdxl_model.versions.get("a00d0b7dcbb9c3fbb34ba87d2d5b46c56969c84a628bf778a7fdaec30b1b99c5")
401
 
402
  prediction = replicate.predictions.create(version=sdxl_version,
403
- input={"prompt": 'Phantasmal iridescent, vibrant color, high contrast, award winning, trending in artstation, digital art' + prompt,
404
- "negative_prompt": 'NSFW, cityscape',
405
  "width": 1648,
406
- "height": 1024}
407
  )
 
408
  prediction.reload()
409
  prediction.wait()
410
 
@@ -412,33 +413,14 @@ def get_image(prompt):
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
 
444
  # def scraping_article(link_scrap):
@@ -447,21 +429,21 @@ iface.launch()
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)
 
400
  sdxl_version = sdxl_model.versions.get("a00d0b7dcbb9c3fbb34ba87d2d5b46c56969c84a628bf778a7fdaec30b1b99c5")
401
 
402
  prediction = replicate.predictions.create(version=sdxl_version,
403
+ input={"prompt":'Phantasmal iridescent, vibrant color, high contrast, award winning, trending in artstation, digital art' + prompt,
404
+ "negative_prompt":'NSFW, cityscape',
405
  "width": 1648,
406
+ "height":1024}
407
  )
408
+ prediction
409
  prediction.reload()
410
  prediction.wait()
411
 
 
413
  print(f"Error: {prediction.error}")
414
  print(f"Last Log")
415
  print(prediction.logs)
416
+ elif ((prediction.status == 'succeeded') | (prediction.output != None)):
 
417
  response = requests.get(prediction.output[0])
418
+ image_data = base64.b64encode(response.content)
419
+ return image_data
420
+ except:
421
+ image_data = None
422
+ return image_data
423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  # return tags, content, url #image, image_data
425
 
426
  # def scraping_article(link_scrap):
 
429
  # return judul, content
430
 
431
 
432
+ with gr.Blocks(theme = "soft", title="Article Writer") as article_generator:
433
+ gr.Markdown(
434
+ """
435
+ # Article Writer
436
+ 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.
437
+ """)
438
+ with gr.Row():
439
+ inputs = gr.Textbox(placeholder="Link Article", show_label=False)
440
+ with gr.Row():
441
+ button_scrap = gr.Button("Scrap Article")
442
+ with gr.Row():
443
+ # title = gr.Textbox("", label="Title")
444
+ # content = gr.Textbox("", label="Content")
445
+ # img_data = gr.Textbox("", label="Content")
446
+ img = gr.Image("", label="Image")
447
+ button_scrap.click(fn=get_image, inputs=inputs, outputs=img)
448
+ if __name__ == "__main__":
449
+ article_generator.launch(share=False)