ginipick commited on
Commit
62ca4c8
ยท
verified ยท
1 Parent(s): d934b2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -114,15 +114,15 @@ def create_ui():
114
  with gr.Row():
115
  with gr.Column(scale=1):
116
  space_table = gr.HTML(create_table_html(formatted_spaces))
 
117
 
118
  with gr.Column(scale=1):
119
  info_output = gr.Textbox(label="Space ์ •๋ณด ๋ฐ ์š”์•ฝ", lines=10)
120
  app_py_content = gr.Code(language="python", label="app.py ๋‚ด์šฉ")
121
 
122
- def on_select(space_index):
123
  try:
124
- space_index = int(space_index)
125
- selected_space = formatted_spaces[space_index]
126
  summary = summarize_space(selected_space)
127
  app_content = get_app_py_content(selected_space['id'])
128
  info = f"์„ ํƒ๋œ Space: {selected_space['name']} (ID: {selected_space['id']})\n"
@@ -136,15 +136,18 @@ def create_ui():
136
  print(traceback.format_exc())
137
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", ""
138
 
139
- demo.load(None, None, None, _js="""
 
140
  function selectSpace(index) {
141
  document.querySelectorAll('button').forEach(btn => btn.classList.remove('selected'));
142
  event.target.classList.add('selected');
143
- gradio('on_select', index);
144
  }
145
- """)
 
 
146
 
147
- demo.load(on_select, None, [info_output, app_py_content], _js="(x) => selectedIndex")
148
 
149
  return demo
150
 
 
114
  with gr.Row():
115
  with gr.Column(scale=1):
116
  space_table = gr.HTML(create_table_html(formatted_spaces))
117
+ selected_index = gr.State(-1)
118
 
119
  with gr.Column(scale=1):
120
  info_output = gr.Textbox(label="Space ์ •๋ณด ๋ฐ ์š”์•ฝ", lines=10)
121
  app_py_content = gr.Code(language="python", label="app.py ๋‚ด์šฉ")
122
 
123
+ def on_select(index):
124
  try:
125
+ selected_space = formatted_spaces[index]
 
126
  summary = summarize_space(selected_space)
127
  app_content = get_app_py_content(selected_space['id'])
128
  info = f"์„ ํƒ๋œ Space: {selected_space['name']} (ID: {selected_space['id']})\n"
 
136
  print(traceback.format_exc())
137
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", ""
138
 
139
+ # JavaScript to handle button clicks
140
+ js_code = """
141
  function selectSpace(index) {
142
  document.querySelectorAll('button').forEach(btn => btn.classList.remove('selected'));
143
  event.target.classList.add('selected');
144
+ selectedIndex.update(index);
145
  }
146
+ """
147
+ demo.load(None, None, None)
148
+ gr.HTML(f"<script>{js_code}</script>")
149
 
150
+ selected_index.change(on_select, inputs=[selected_index], outputs=[info_output, app_py_content])
151
 
152
  return demo
153