Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,3 @@
|
|
| 1 |
-
# import gradio as gr
|
| 2 |
-
# import time
|
| 3 |
-
|
| 4 |
-
# def update_options(selected_option):
|
| 5 |
-
# new_options = [selected_option + str(x) for x in range(1, 4)]
|
| 6 |
-
# return gr.Dropdown(choices=new_options, interactive=True)
|
| 7 |
-
|
| 8 |
-
# with gr.Blocks() as interface:
|
| 9 |
-
# dropdown = gr.Dropdown(choices=["Anna", "Christine", "Phoebe"])
|
| 10 |
-
# dropdown2 = gr.Dropdown(choices=["Anna", "Christine", "Phoebe"], allow_custom_value=True)
|
| 11 |
-
# dropdown.change(update_options, dropdown, dropdown2)
|
| 12 |
-
|
| 13 |
-
# interface.launch()
|
| 14 |
-
|
| 15 |
import gradio as gr
|
| 16 |
import plotly.graph_objects as go
|
| 17 |
import os
|
|
@@ -90,59 +76,18 @@ def display_tree():
|
|
| 90 |
fig = go.Figure(data=[edge_trace, node_trace], layout=layout)
|
| 91 |
return fig
|
| 92 |
|
| 93 |
-
def display_image_based_on_dropdown_1(dropdown_value):
|
| 94 |
-
# Create a white image
|
| 95 |
-
img = Image.new('RGB', (200, 100), color='white')
|
| 96 |
-
d = ImageDraw.Draw(img)
|
| 97 |
-
|
| 98 |
-
# Specify a font. If you have a .ttf font file you can specify its path
|
| 99 |
-
# fnt = ImageFont.truetype('/path/to/font.ttf', 40)
|
| 100 |
-
# Otherwise, we'll use a default PIL font
|
| 101 |
-
fnt = ImageFont.load_default()
|
| 102 |
-
|
| 103 |
-
# Position the text in the center
|
| 104 |
-
text = "Placeholder"
|
| 105 |
-
textwidth, textheight = d.textsize(text, font=fnt)
|
| 106 |
-
width, height = img.size
|
| 107 |
-
x = (width - textwidth) / 2
|
| 108 |
-
y = (height - textheight) / 2
|
| 109 |
|
| 110 |
-
# Draw the text onto the image
|
| 111 |
-
d.text((x,y), text, font=fnt, fill='black')
|
| 112 |
-
|
| 113 |
-
# Save the image to a file in buffer to return
|
| 114 |
-
img.save('/tmp/dummy_image.png')
|
| 115 |
-
|
| 116 |
-
return '/tmp/dummy_image.png'
|
| 117 |
-
|
| 118 |
-
def display_image_based_on_dropdown_2(dropdown_value):
|
| 119 |
-
# Create a white image
|
| 120 |
-
img = Image.new('RGB', (200, 100), color='white')
|
| 121 |
-
d = ImageDraw.Draw(img)
|
| 122 |
-
|
| 123 |
-
# Specify a font. If you have a .ttf font file you can specify its path
|
| 124 |
-
# fnt = ImageFont.truetype('/path/to/font.ttf', 40)
|
| 125 |
-
# Otherwise, we'll use a default PIL font
|
| 126 |
-
fnt = ImageFont.load_default()
|
| 127 |
-
|
| 128 |
-
# Position the text in the center
|
| 129 |
-
text = "Placeholder"
|
| 130 |
-
textwidth, textheight = d.textsize(text, font=fnt)
|
| 131 |
-
width, height = img.size
|
| 132 |
-
x = (width - textwidth) / 2
|
| 133 |
-
y = (height - textheight) / 2
|
| 134 |
-
|
| 135 |
-
# Draw the text onto the image
|
| 136 |
-
d.text((x,y), text, font=fnt, fill='black')
|
| 137 |
-
|
| 138 |
-
# Save the image to a file in buffer to return
|
| 139 |
-
img.save('/tmp/dummy_image.png')
|
| 140 |
-
|
| 141 |
-
return '/tmp/dummy_image.png'
|
| 142 |
|
| 143 |
def get_protoIDs(nodename):
|
| 144 |
return gr.Dropdown(choices=nodename_to_protoIDs[nodename], interactive=True)
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
with gr.Blocks() as demo:
|
| 147 |
gr.Markdown("## Interactive Tree and Image Display")
|
| 148 |
|
|
@@ -160,6 +105,7 @@ with gr.Blocks() as demo:
|
|
| 160 |
image_output_2 = gr.Image('new_teaser (3)-1.png')
|
| 161 |
|
| 162 |
dropdown_1_nodename.change(get_protoIDs, dropdown_1_nodename, dropdown_1_protos)
|
|
|
|
| 163 |
dropdown_2_nodename.change(get_protoIDs, dropdown_2_nodename, dropdown_2_protos)
|
| 164 |
|
| 165 |
# Initialize with placeholder images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import plotly.graph_objects as go
|
| 3 |
import os
|
|
|
|
| 76 |
fig = go.Figure(data=[edge_trace, node_trace], layout=layout)
|
| 77 |
return fig
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
def get_protoIDs(nodename):
|
| 82 |
return gr.Dropdown(choices=nodename_to_protoIDs[nodename], interactive=True)
|
| 83 |
|
| 84 |
+
|
| 85 |
+
def get_image(nodename, protoID):
|
| 86 |
+
imgname = '-'.join([nodename, protoID]) + '.png'
|
| 87 |
+
filepath = imgname_to_filepath[imgname]
|
| 88 |
+
return gr.Image(filepath)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
with gr.Blocks() as demo:
|
| 92 |
gr.Markdown("## Interactive Tree and Image Display")
|
| 93 |
|
|
|
|
| 105 |
image_output_2 = gr.Image('new_teaser (3)-1.png')
|
| 106 |
|
| 107 |
dropdown_1_nodename.change(get_protoIDs, dropdown_1_nodename, dropdown_1_protos)
|
| 108 |
+
dropdown_1_protos.change(get_image, [dropdown_1_nodename, dropdown_1_protos], image_output_1)
|
| 109 |
dropdown_2_nodename.change(get_protoIDs, dropdown_2_nodename, dropdown_2_protos)
|
| 110 |
|
| 111 |
# Initialize with placeholder images
|