GoBoKyung commited on
Commit
abbed59
·
1 Parent(s): 15a8c0d
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -5,6 +5,7 @@ import numpy as np
5
  from PIL import Image
6
  import tensorflow as tf
7
  from transformers import SegformerFeatureExtractor, TFSegformerForSemanticSegmentation
 
8
 
9
  feature_extractor = SegformerFeatureExtractor.from_pretrained(
10
  "nvidia/segformer-b1-finetuned-cityscapes-1024-1024"
@@ -75,6 +76,10 @@ def draw_plot(pred_img, seg):
75
  return fig
76
 
77
  def sepia(input_text):
 
 
 
 
78
  # Load the image using the input text (assumed to be a path to an image)
79
  input_img = Image.open(input_text)
80
 
@@ -97,13 +102,13 @@ def sepia(input_text):
97
  pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
98
  pred_img = pred_img.astype(np.uint8)
99
 
100
- fig = draw_plot(pred_img, seg)
101
- return fig
 
 
102
 
103
- demo = gr.Interface(fn=sepia,
104
- inputs=gr.Textbox(text="Enter text here"),
105
- outputs=['plot'],
106
- examples=["img_1.jpg", "img_2.jpeg", "img_3.jpg", "img_4.jpg", "img_5.png"],
107
- allow_flagging='never')
108
 
109
- demo.launch()
 
 
5
  from PIL import Image
6
  import tensorflow as tf
7
  from transformers import SegformerFeatureExtractor, TFSegformerForSemanticSegmentation
8
+ import os
9
 
10
  feature_extractor = SegformerFeatureExtractor.from_pretrained(
11
  "nvidia/segformer-b1-finetuned-cityscapes-1024-1024"
 
76
  return fig
77
 
78
  def sepia(input_text):
79
+ # Check if the input text is a valid file path
80
+ if not os.path.isfile(input_text):
81
+ return "Invalid file path. Please enter a valid image file path."
82
+
83
  # Load the image using the input text (assumed to be a path to an image)
84
  input_img = Image.open(input_text)
85
 
 
102
  pred_img = np.array(input_img) * 0.5 + color_seg * 0.5
103
  pred_img = pred_img.astype(np.uint8)
104
 
105
+ # Convert the image array to a format suitable for Gradio
106
+ pred_img = Image.fromarray(pred_img)
107
+
108
+ return pred_img
109
 
110
+ # Define the Gradio interface
111
+ iface = gr.Interface(fn=sepia, inputs="image", outputs="image")
 
 
 
112
 
113
+ # Launch the Gradio app
114
+ iface.launch()