ginipick commited on
Commit
9c9264e
ยท
verified ยท
1 Parent(s): 7cb753c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -110,20 +110,22 @@ def create_ui():
110
 
111
  space_choices = {f"{space['name']} by {space['author']} (Likes: {space['likes']})": space['id'] for space in formatted_spaces}
112
 
113
- with gr.Blocks(css="#space-list { height: 400px; overflow-y: auto; }") as demo:
114
  gr.Markdown("# Hugging Face Most Liked Spaces")
115
 
116
  with gr.Row():
117
  with gr.Column(scale=1):
118
- with gr.Box(elem_id="space-list"):
 
119
  for space in formatted_spaces:
120
  with gr.Row():
121
- gr.Radio(
122
  choices=[f"{space['name']} by {space['author']} (Likes: {space['likes']})"],
123
  label="",
124
  value=None,
125
- name=space['id']
126
  )
 
127
  gr.Button("๐Ÿ”—", elem_id=f"link-{space['id']}")
128
  summarize_btn = gr.Button("์š”์•ฝ")
129
 
@@ -134,7 +136,7 @@ def create_ui():
134
  def on_select(choice):
135
  try:
136
  print(f"Selected: {choice}") # ๋””๋ฒ„๊น… ์ถœ๋ ฅ
137
- selected_id = space_choices[choice]
138
  selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
139
  if selected_space:
140
  app_content = get_app_py_content(selected_id)
@@ -151,7 +153,7 @@ def create_ui():
151
  def on_summarize(choice):
152
  try:
153
  if choice:
154
- selected_id = space_choices[choice]
155
  selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
156
  if selected_space:
157
  summary = summarize_space(selected_space)
@@ -164,11 +166,10 @@ def create_ui():
164
  print(traceback.format_exc()) # ์ƒ์„ธํ•œ ์˜ค๋ฅ˜ ์ •๋ณด ์ถœ๋ ฅ
165
  return f"์š”์•ฝ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
166
 
167
- for space in formatted_spaces:
168
- radio = demo.components[0].children[0].children[0].children[0].children[formatted_spaces.index(space)].children[0]
169
  radio.change(on_select, radio, [output, app_py_content])
170
 
171
- summarize_btn.click(on_summarize, inputs=[gr.State(lambda: next(radio for radio in demo.components[0].children[0].children[0].children[0].children if radio.children[0].value))], outputs=[output])
172
 
173
  # JavaScript to open links in new tabs
174
  link_script = """
 
110
 
111
  space_choices = {f"{space['name']} by {space['author']} (Likes: {space['likes']})": space['id'] for space in formatted_spaces}
112
 
113
+ with gr.Blocks(css="#space-list { max-height: 400px; overflow-y: auto; }") as demo:
114
  gr.Markdown("# Hugging Face Most Liked Spaces")
115
 
116
  with gr.Row():
117
  with gr.Column(scale=1):
118
+ with gr.Column(elem_id="space-list"):
119
+ space_radios = []
120
  for space in formatted_spaces:
121
  with gr.Row():
122
+ radio = gr.Radio(
123
  choices=[f"{space['name']} by {space['author']} (Likes: {space['likes']})"],
124
  label="",
125
  value=None,
126
+ elem_id=f"radio-{space['id']}"
127
  )
128
+ space_radios.append(radio)
129
  gr.Button("๐Ÿ”—", elem_id=f"link-{space['id']}")
130
  summarize_btn = gr.Button("์š”์•ฝ")
131
 
 
136
  def on_select(choice):
137
  try:
138
  print(f"Selected: {choice}") # ๋””๋ฒ„๊น… ์ถœ๋ ฅ
139
+ selected_id = space_choices[choice[0]] # choice is now a list with one item
140
  selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
141
  if selected_space:
142
  app_content = get_app_py_content(selected_id)
 
153
  def on_summarize(choice):
154
  try:
155
  if choice:
156
+ selected_id = space_choices[choice[0]] # choice is now a list with one item
157
  selected_space = next((space for space in formatted_spaces if space['id'] == selected_id), None)
158
  if selected_space:
159
  summary = summarize_space(selected_space)
 
166
  print(traceback.format_exc()) # ์ƒ์„ธํ•œ ์˜ค๋ฅ˜ ์ •๋ณด ์ถœ๋ ฅ
167
  return f"์š”์•ฝ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
168
 
169
+ for radio in space_radios:
 
170
  radio.change(on_select, radio, [output, app_py_content])
171
 
172
+ summarize_btn.click(on_summarize, inputs=[gr.State(lambda: next((radio for radio in space_radios if radio.value), None))], outputs=[output])
173
 
174
  # JavaScript to open links in new tabs
175
  link_script = """