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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -36
app.py CHANGED
@@ -94,41 +94,30 @@ def create_ui():
94
  formatted_spaces = format_spaces(spaces_list)
95
  print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋””๋ฒ„๊น… ์ถœ๋ ฅ
96
 
97
- def create_table_html(spaces):
98
- html = "<table><tr><th>Title</th><th>Author</th><th>Likes</th><th>Action</th></tr>"
99
- for i, space in enumerate(spaces):
100
- html += f"""
101
- <tr>
102
- <td>{space['name']}</td>
103
- <td>{space['author']}</td>
104
- <td>{space['likes']}</td>
105
- <td><button onclick="selectSpace({i})">ํด๋ฆญ</button></td>
106
- </tr>
107
- """
108
- html += "</table>"
109
- return html
110
-
111
  with gr.Blocks() as demo:
112
  gr.Markdown("# Hugging Face Most Liked Spaces")
113
 
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"
129
- info += f"Author: {selected_space['author']}\n"
130
- info += f"Likes: {selected_space['likes']}\n"
131
- info += f"URL: {selected_space['url']}\n\n"
132
  info += f"์š”์•ฝ:\n{summary}"
133
  return info, app_content
134
  except Exception as e:
@@ -136,18 +125,8 @@ def create_ui():
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
 
 
94
  formatted_spaces = format_spaces(spaces_list)
95
  print(f"Total spaces loaded: {len(formatted_spaces)}") # ๋””๋ฒ„๊น… ์ถœ๋ ฅ
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  with gr.Blocks() as demo:
98
  gr.Markdown("# Hugging Face Most Liked Spaces")
99
 
100
  with gr.Row():
101
  with gr.Column(scale=1):
102
+ space_buttons = []
103
+ for space in formatted_spaces:
104
+ with gr.Row():
105
+ gr.Markdown(f"{space['name']} by {space['author']} (Likes: {space['likes']})")
106
+ button = gr.Button("ํด๋ฆญ", elem_id=f"btn-{space['id']}")
107
+ space_buttons.append(button)
108
 
109
  with gr.Column(scale=1):
110
  info_output = gr.Textbox(label="Space ์ •๋ณด ๋ฐ ์š”์•ฝ", lines=10)
111
  app_py_content = gr.Code(language="python", label="app.py ๋‚ด์šฉ")
112
 
113
+ def on_select(space):
114
  try:
115
+ summary = summarize_space(space)
116
+ app_content = get_app_py_content(space['id'])
117
+ info = f"์„ ํƒ๋œ Space: {space['name']} (ID: {space['id']})\n"
118
+ info += f"Author: {space['author']}\n"
119
+ info += f"Likes: {space['likes']}\n"
120
+ info += f"URL: {space['url']}\n\n"
 
121
  info += f"์š”์•ฝ:\n{summary}"
122
  return info, app_content
123
  except Exception as e:
 
125
  print(traceback.format_exc())
126
  return f"์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", ""
127
 
128
+ for button, space in zip(space_buttons, formatted_spaces):
129
+ button.click(on_select, inputs=[gr.State(space)], outputs=[info_output, app_py_content])
 
 
 
 
 
 
 
 
 
 
130
 
131
  return demo
132