Zaherrr commited on
Commit
dfe5fc6
1 Parent(s): 8c1382e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -27,6 +27,9 @@ def reshape_json_data_to_fit_visualize_graph(graph_data):
27
  def display_example(index):
28
  example = dataset[index]
29
  img = example["image"]
 
 
 
30
 
31
  # Prepare the graph data
32
  graph_data = {"nodes": example["nodes"], "edges": example["edges"]}
@@ -41,12 +44,12 @@ def display_example(index):
41
  # Convert graph_data to a formatted JSON string
42
  json_data = json.dumps(transformed_graph_data, indent=2)
43
 
44
- return img, graph_html, json_data, transformed_graph_data
45
 
46
  def create_interface():
47
  with gr.Blocks() as demo:
48
 
49
- gr.Markdown("# Knowledge Graph Visualizer for the [Zaherrr/OOP_KG_Dataset](https://huggingface.co/datasets/Zaherrr/OOP_KG_Dataset)")
50
 
51
  with gr.Row():
52
  index_slider = gr.Slider(
@@ -59,7 +62,14 @@ def create_interface():
59
  with gr.Row():
60
  image_output = gr.Image(type="pil", label="Image", height=500)
61
  graph_output = gr.HTML(label="Knowledge Graph")
62
-
 
 
 
 
 
 
 
63
  with gr.Row():
64
  json_output = gr.Code(language="json", label="Graph JSON Data")
65
  text_output = gr.Textbox(
@@ -71,7 +81,7 @@ def create_interface():
71
  index_slider.change(
72
  fn=display_example,
73
  inputs=[index_slider],
74
- outputs=[image_output, graph_output, json_output, text_output],
75
  )
76
 
77
  return demo
 
27
  def display_example(index):
28
  example = dataset[index]
29
  img = example["image"]
30
+
31
+ # Get image dimensions
32
+ img_width, img_height = img.size
33
 
34
  # Prepare the graph data
35
  graph_data = {"nodes": example["nodes"], "edges": example["edges"]}
 
44
  # Convert graph_data to a formatted JSON string
45
  json_data = json.dumps(transformed_graph_data, indent=2)
46
 
47
+ return img, graph_html, json_data, transformed_graph_data, f"Width: {img_width}px, Height: {img_height}px"
48
 
49
  def create_interface():
50
  with gr.Blocks() as demo:
51
 
52
+ gr.Markdown("# Knowledge Graph Visualizer for the [Zaherrr/OOP_KG_Dataset](https://huggingface.co/datasets/Zaherrr/OOP_KG_Dataset) dataset")
53
 
54
  with gr.Row():
55
  index_slider = gr.Slider(
 
62
  with gr.Row():
63
  image_output = gr.Image(type="pil", label="Image", height=500)
64
  graph_output = gr.HTML(label="Knowledge Graph")
65
+
66
+ with gr.Row():
67
+ dimensions_output = gr.Textbox(
68
+ label="Image Dimensions (pixels)",
69
+ placeholder="Width and Height will appear here",
70
+ interactive=False,
71
+ )
72
+
73
  with gr.Row():
74
  json_output = gr.Code(language="json", label="Graph JSON Data")
75
  text_output = gr.Textbox(
 
81
  index_slider.change(
82
  fn=display_example,
83
  inputs=[index_slider],
84
+ outputs=[image_output, graph_output, json_output, text_output, dimensions_output],
85
  )
86
 
87
  return demo