simayhosmeyve commited on
Commit
04e8f54
1 Parent(s): 19f0845

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -512,6 +512,50 @@ def result(Input,Choice):
512
  Psnr = 20 * math.log10(MAX / math.sqrt(mse))
513
  return Input,Psnr
514
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
  if Choice=="Enhancement":
516
  pre_trained2 = tf.keras.models.load_model("gradio_pix2pix.h5")
517
  size0 = Input.shape[0]
@@ -533,6 +577,6 @@ def result(Input,Choice):
533
 
534
  import gradio as gr
535
 
536
- iface = gr.Interface(fn=result, inputs=[gr.inputs.Image(type="numpy",image_mode="RGB"),gr.inputs.Radio(["Coloring","Enhancement","Repair","Repair and Color"])], outputs=[gr.outputs.Image( type="auto", label="Output"),gr.outputs.Textbox(type="number",label="Psnr")],theme="grass",live=True
537
  ,css=""" body {background-color: rgba(127,191,63,0.48)} """,title="Image Enhancement",article=""" <a href="https://docs.google.com/document/d/19k6dyR5x_hd1M0yoU8i49dlDWvFmtnBT/edit?usp=sharing&ouid=115743073712072785012&rtpof=true&sd=true" download="example.docx"><img src="https://img.icons8.com/external-itim2101-lineal-color-itim2101/64/000000/external-article-blogger-and-influencer-itim2101-lineal-color-itim2101-1.png" alt="Article"></a>""",examples=[["dog.jpg","Coloring"],["woman.png","Coloring"]])
538
  iface.launch(debug="True",show_tips="True",inbrowser=True)
 
512
  Psnr = 20 * math.log10(MAX / math.sqrt(mse))
513
  return Input,Psnr
514
 
515
+ if Choice=="Indoor-Coloring":
516
+ pre_trained = tf.keras.models.load_model("gradio_pix2pix.h5")
517
+ size0 = Input.shape[0]
518
+ size1 = Input.shape[1]
519
+ start = Input
520
+ Input = cv2.resize(Input, (256,256), interpolation = cv2.INTER_AREA)
521
+ Input = cv2.cvtColor(Input , cv2.COLOR_BGR2GRAY)
522
+ Input = np.array(Input).reshape(1,256,256,1)
523
+ prediction = pre_trained(Input,training=True)
524
+ Input = prediction[0]
525
+ Input = (Input+1)*127.5
526
+ Input = np.uint8(Input)
527
+ Input = cv2.resize(Input, (size1,size0), interpolation = cv2.INTER_AREA)
528
+ finish = Input
529
+ mse = np.mean((start - finish) ** 2)
530
+ MAX = np.iinfo(start.dtype).max
531
+ if mse == 0:
532
+ Psnr = 100
533
+ else:
534
+ Psnr = 20 * math.log10(MAX / math.sqrt(mse))
535
+ return Input,Psnr
536
+
537
+ if Choice=="Outdoor-Coloring":
538
+ pre_trained = tf.keras.models.load_model("gradio_pix2pix.h5")
539
+ size0 = Input.shape[0]
540
+ size1 = Input.shape[1]
541
+ start = Input
542
+ Input = cv2.resize(Input, (256,256), interpolation = cv2.INTER_AREA)
543
+ Input = cv2.cvtColor(Input , cv2.COLOR_BGR2GRAY)
544
+ Input = np.array(Input).reshape(1,256,256,1)
545
+ prediction = pre_trained(Input,training=True)
546
+ Input = prediction[0]
547
+ Input = (Input+1)*127.5
548
+ Input = np.uint8(Input)
549
+ Input = cv2.resize(Input, (size1,size0), interpolation = cv2.INTER_AREA)
550
+ finish = Input
551
+ mse = np.mean((start - finish) ** 2)
552
+ MAX = np.iinfo(start.dtype).max
553
+ if mse == 0:
554
+ Psnr = 100
555
+ else:
556
+ Psnr = 20 * math.log10(MAX / math.sqrt(mse))
557
+ return Input,Psnr
558
+
559
  if Choice=="Enhancement":
560
  pre_trained2 = tf.keras.models.load_model("gradio_pix2pix.h5")
561
  size0 = Input.shape[0]
 
577
 
578
  import gradio as gr
579
 
580
+ iface = gr.Interface(fn=result, inputs=[gr.inputs.Image(type="numpy",image_mode="RGB"),gr.inputs.Radio(["Indoor-Coloring","Outdoor-Coloring","Enhancement","Repair","Repair and Color"])], outputs=[gr.outputs.Image( type="auto", label="Output"),gr.outputs.Textbox(type="number",label="Psnr")],theme="grass",live=True
581
  ,css=""" body {background-color: rgba(127,191,63,0.48)} """,title="Image Enhancement",article=""" <a href="https://docs.google.com/document/d/19k6dyR5x_hd1M0yoU8i49dlDWvFmtnBT/edit?usp=sharing&ouid=115743073712072785012&rtpof=true&sd=true" download="example.docx"><img src="https://img.icons8.com/external-itim2101-lineal-color-itim2101/64/000000/external-article-blogger-and-influencer-itim2101-lineal-color-itim2101-1.png" alt="Article"></a>""",examples=[["dog.jpg","Coloring"],["woman.png","Coloring"]])
582
  iface.launch(debug="True",show_tips="True",inbrowser=True)