Skip to content

Commit

Permalink
[#6] Fix: Load image when click on example
Browse files Browse the repository at this point in the history
  • Loading branch information
jiooum committed Oct 13, 2024
1 parent 3071ff5 commit ac212c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
8 changes: 6 additions & 2 deletions gradio_demo/getting_started/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def btn_start_demo_clicked(self):
session_id = self.create_new_session()
return session_id, gradio.Row(visible=True), gradio.Button(visible=False), gradio.Textbox(visible=True)

def btn_load_examples_clicked(self):
records = self.__mongo_db.get_latest_requests()
def get_examples(self, limit: int = 5):
records = self.__mongo_db.get_latest_requests(limit=limit)
_examples = []
for record in records:
request_id = str(record["_id"])
Expand All @@ -110,6 +110,10 @@ def btn_load_examples_clicked(self):
_input.guidance_scale,
]
)
return _examples

def btn_load_examples_clicked(self):
_examples = self.get_examples(limit=50)
return gradio.Dataset(samples=_examples, visible=True)

def load_image_url(self, request_id: str) -> str:
Expand Down
15 changes: 2 additions & 13 deletions gradio_demo/getting_started/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,7 @@ def make_app_ui(

with gradio.Column(show_progress=True):
examples = gradio.Examples(
examples=[
[
"",
"",
"",
0,
0,
0,
0,
0,
]
],
examples=[app_controller.get_examples(limit=5)],
inputs=[
request_id,
input_prompt,
Expand Down Expand Up @@ -121,7 +110,7 @@ def make_app_ui(
output_url.change(app_controller.update_output_url, [session_id, output_url])
output_image.change(app_controller.update_output_image, [session_id, output_image])

examples.dataset.click(app_controller.load_image_url, [request_id], [output_image])
examples.load_input_event.success(app_controller.load_image_url, [request_id], [output_image])

btn_load_examples.click(app_controller.btn_load_examples_clicked, None, [examples.dataset])
btn_clear.add(
Expand Down

0 comments on commit ac212c7

Please sign in to comment.