pablovela5620 commited on
Commit
062711f
1 Parent(s): f0d4b35

add cached examples

Browse files
Files changed (2) hide show
  1. gradio_demo.py +29 -16
  2. living_room.jpeg +0 -0
gradio_demo.py CHANGED
@@ -88,7 +88,7 @@ def log_images_segmentation(
88
 
89
 
90
  # Gradio stuff
91
- def predict():
92
  file_name = f"{datetime.utcnow().strftime('%s')}.html"
93
  file_path = static_dir / file_name
94
  rec = rr.memory_recording()
@@ -102,26 +102,22 @@ def predict():
102
 
103
  predictor = SamPredictor(sam)
104
 
105
- # prompt = "tires"
 
 
 
 
 
 
106
 
107
- log_video_segmentation(
108
- Path("dog_and_woman.mp4"),
109
- "dog, woman",
110
  model,
111
  predictor,
112
  device=device,
113
  )
114
 
115
- # log_images_segmentation(
116
- # [
117
- # "https://raw.githubusercontent.com/facebookresearch/segment-anything/main/notebooks/images/truck.jpg"
118
- # ],
119
- # prompt,
120
- # model,
121
- # predictor,
122
- # device=device,
123
- # )
124
-
125
  with open(file_path, "w") as f:
126
  f.write(rec.as_html())
127
  iframe = f"""<iframe src="/static/{file_name}" width="950" height="712"></iframe>"""
@@ -130,8 +126,25 @@ def predict():
130
 
131
  with gr.Blocks() as block:
132
  with gr.Row():
133
- html = gr.HTML(label="HTML preview", show_label=True, value=predict())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
 
135
  # mount Gradio app to FastAPI app
136
  app = gr.mount_gradio_app(app, block, path="/")
137
 
 
88
 
89
 
90
  # Gradio stuff
91
+ def predict(prompt: str, image_path: str):
92
  file_name = f"{datetime.utcnow().strftime('%s')}.html"
93
  file_path = static_dir / file_name
94
  rec = rr.memory_recording()
 
102
 
103
  predictor = SamPredictor(sam)
104
 
105
+ # log_video_segmentation(
106
+ # Path("dog_and_woman.mp4"),
107
+ # "dog, woman",
108
+ # model,
109
+ # predictor,
110
+ # device=device,
111
+ # )
112
 
113
+ log_images_segmentation(
114
+ [image_path],
115
+ prompt,
116
  model,
117
  predictor,
118
  device=device,
119
  )
120
 
 
 
 
 
 
 
 
 
 
 
121
  with open(file_path, "w") as f:
122
  f.write(rec.as_html())
123
  iframe = f"""<iframe src="/static/{file_name}" width="950" height="712"></iframe>"""
 
126
 
127
  with gr.Blocks() as block:
128
  with gr.Row():
129
+ with gr.Column():
130
+ text_input = gr.Textbox(value="tires, wheels", label="Prompt")
131
+ new_btn = gr.Button("Segment")
132
+ with gr.Column():
133
+ image = gr.Image(label="Image", type="filepath")
134
+ with gr.Row():
135
+ html = gr.HTML(label="HTML preview", show_label=True)
136
+ with gr.Row():
137
+ gr.Examples(
138
+ [
139
+ ["fan, mirror, sofa", "living_room.jpeg"],
140
+ ],
141
+ fn=predict,
142
+ inputs=[text_input, image],
143
+ outputs=[html],
144
+ cache_examples=True,
145
+ )
146
 
147
+ new_btn.click(fn=predict, inputs=[text_input, image], outputs=[html])
148
  # mount Gradio app to FastAPI app
149
  app = gr.mount_gradio_app(app, block, path="/")
150
 
living_room.jpeg ADDED