Spaces:
Running
Running
xiaohang07
commited on
Commit
•
8f98f3c
1
Parent(s):
6f64ceb
Update app.py
Browse files
app.py
CHANGED
@@ -78,7 +78,13 @@ with gr.Blocks() as iface:
|
|
78 |
with gr.Tab("CIF-SLICES Conversion"):
|
79 |
with gr.Row():
|
80 |
with gr.Column():
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
convert_cif_button = gr.Button("Convert CIF to SLICES")
|
83 |
slices_input = gr.Textbox(label="Enter SLICES String")
|
84 |
convert_slices_button = gr.Button("Convert SLICES to CIF")
|
@@ -96,23 +102,36 @@ with gr.Blocks() as iface:
|
|
96 |
augment_button = gr.Button("Augment and Canonicalize")
|
97 |
aug_slices_output = gr.Textbox(label="Augmented SLICES Strings")
|
98 |
canon_slices_output = gr.Textbox(label="Canonical SLICES Strings")
|
99 |
-
|
100 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
convert_cif_button.click(
|
102 |
-
cif_to_slices,
|
103 |
-
inputs=[
|
104 |
outputs=[slices_output, cif_image, conversion_status, slices_input, aug_slices_input]
|
105 |
)
|
|
|
106 |
convert_slices_button.click(
|
107 |
slices_to_cif,
|
108 |
inputs=[slices_input],
|
109 |
outputs=[cif_output, slices_image, conversion_status]
|
110 |
)
|
|
|
111 |
augment_button.click(
|
112 |
augment_and_canonicalize_slices,
|
113 |
inputs=[aug_slices_input, num_augmentations],
|
114 |
outputs=[aug_slices_output, canon_slices_output]
|
115 |
)
|
116 |
|
117 |
-
# Launch the interface
|
118 |
iface.launch(share=True)
|
|
|
78 |
with gr.Tab("CIF-SLICES Conversion"):
|
79 |
with gr.Row():
|
80 |
with gr.Column():
|
81 |
+
file_choice = gr.Radio(
|
82 |
+
["Use example CIF (NdSiRu.cif)", "Upload custom CIF"],
|
83 |
+
label="Choose CIF source",
|
84 |
+
value="Use example CIF (NdSiRu.cif)"
|
85 |
+
)
|
86 |
+
example_file = gr.File(value="NdSiRu.cif", visible=False, interactive=False)
|
87 |
+
custom_file = gr.File(label="Upload CIF file", file_types=[".cif"], visible=False)
|
88 |
convert_cif_button = gr.Button("Convert CIF to SLICES")
|
89 |
slices_input = gr.Textbox(label="Enter SLICES String")
|
90 |
convert_slices_button = gr.Button("Convert SLICES to CIF")
|
|
|
102 |
augment_button = gr.Button("Augment and Canonicalize")
|
103 |
aug_slices_output = gr.Textbox(label="Augmented SLICES Strings")
|
104 |
canon_slices_output = gr.Textbox(label="Canonical SLICES Strings")
|
105 |
+
|
106 |
# Event handlers
|
107 |
+
def update_file_visibility(choice):
|
108 |
+
return gr.update(visible=choice == "Use example CIF (NdSiRu.cif)"), gr.update(visible=choice == "Upload custom CIF")
|
109 |
+
|
110 |
+
file_choice.change(
|
111 |
+
update_file_visibility,
|
112 |
+
inputs=[file_choice],
|
113 |
+
outputs=[example_file, custom_file]
|
114 |
+
)
|
115 |
+
|
116 |
+
def get_active_file(choice, example, custom):
|
117 |
+
return example if choice == "Use example CIF (NdSiRu.cif)" else custom
|
118 |
+
|
119 |
convert_cif_button.click(
|
120 |
+
lambda choice, example, custom: cif_to_slices(get_active_file(choice, example, custom)),
|
121 |
+
inputs=[file_choice, example_file, custom_file],
|
122 |
outputs=[slices_output, cif_image, conversion_status, slices_input, aug_slices_input]
|
123 |
)
|
124 |
+
|
125 |
convert_slices_button.click(
|
126 |
slices_to_cif,
|
127 |
inputs=[slices_input],
|
128 |
outputs=[cif_output, slices_image, conversion_status]
|
129 |
)
|
130 |
+
|
131 |
augment_button.click(
|
132 |
augment_and_canonicalize_slices,
|
133 |
inputs=[aug_slices_input, num_augmentations],
|
134 |
outputs=[aug_slices_output, canon_slices_output]
|
135 |
)
|
136 |
|
|
|
137 |
iface.launch(share=True)
|