ginipick commited on
Commit
c5ce4c9
ยท
verified ยท
1 Parent(s): ea30dcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -20
app.py CHANGED
@@ -89,7 +89,7 @@ def analyze_code(app_content: str) -> str:
89
  C. ํŠน์žฅ์ 
90
  D. ์ ์šฉ ๋Œ€์ƒ ๋ฐ ํƒ€๊ฒŸ
91
  E. ๊ธฐ๋Œ€ํšจ๊ณผ
92
- ๊ธฐ์กด ๋ฐ ์œ ์‚ฌ ํ”„๋กœ์ ํŠธ์™€ ๋น„๊ตํ•˜์—ฌ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”."""
93
  user_message = f"๋‹ค์Œ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
94
 
95
  messages = [
@@ -104,7 +104,7 @@ def analyze_code(app_content: str) -> str:
104
  return f"๋ถ„์„ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
105
 
106
  def explain_usage(app_content: str) -> str:
107
- system_message = "๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋ฒ•์„ ์ƒ์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”."
108
  user_message = f"๋‹ค์Œ Python ์ฝ”๋“œ์˜ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
109
 
110
  messages = [
@@ -118,18 +118,27 @@ def explain_usage(app_content: str) -> str:
118
  except Exception as e:
119
  return f"์‚ฌ์šฉ๋ฒ• ์„ค๋ช… ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
120
 
121
- def analyze_space(url: str):
122
  try:
123
  space_id = url.split('spaces/')[-1]
124
 
 
 
 
 
 
125
  app_content = get_file_content(space_id, "app.py")
 
 
126
  summary = summarize_code(app_content)
 
 
127
  analysis = analyze_code(app_content)
128
- usage = explain_usage(app_content)
129
 
130
- tree_structure = get_space_structure(space_id)
131
- tree_view = format_tree_structure(tree_structure)
132
 
 
133
  return summary, analysis, usage, app_content, tree_view, tree_structure, space_id
134
  except Exception as e:
135
  print(f"Error in analyze_space: {str(e)}")
@@ -147,12 +156,12 @@ def create_ui():
147
  margin-bottom: 20px;
148
  }
149
  .scroll-lock {
150
- overflow: auto !important;
151
- max-height: none !important;
152
- height: calc(100vh - 200px) !important;
153
  }
154
  .full-height {
155
  height: calc(100vh - 200px) !important;
 
156
  }
157
  """
158
 
@@ -165,26 +174,27 @@ def create_ui():
165
  analyze_button = gr.Button("๋ถ„์„")
166
 
167
  with gr.Group(elem_classes="output-group scroll-lock"):
168
- summary_output = gr.Textbox(label="์š”์•ฝ (3์ค„ ์ด๋‚ด)", lines=3)
169
 
170
  with gr.Group(elem_classes="output-group scroll-lock"):
171
- analysis_output = gr.Textbox(label="๋ถ„์„", lines=15)
172
 
173
  with gr.Group(elem_classes="output-group scroll-lock"):
174
- usage_output = gr.Textbox(label="์‚ฌ์šฉ๋ฒ•", lines=10)
175
 
176
  with gr.Group(elem_classes="output-group scroll-lock"):
177
  tree_view_output = gr.Textbox(label="ํŒŒ์ผ ๊ตฌ์กฐ (Tree View)", lines=20)
178
 
179
- file_buttons = gr.Dataframe(
180
- headers=["ํŒŒ์ผ ์ด๋ฆ„", "์—ด๊ธฐ"],
181
- datatype=["str", "html"],
182
- col_count=(2, "fixed"),
183
- label="ํŒŒ์ผ ๋ฆฌ์ŠคํŠธ"
184
- )
 
185
 
186
  with gr.Column(scale=4): # ์˜ค๋ฅธ์ชฝ 40%
187
- with gr.Group(elem_classes="output-group scroll-lock full-height"):
188
  code_tabs = gr.Tabs()
189
  with code_tabs:
190
  app_py_tab = gr.TabItem("app.py")
@@ -247,7 +257,17 @@ if __name__ == "__main__":
247
  try:
248
  demo = create_ui()
249
  demo.queue()
250
- demo.launch()
 
 
 
 
 
 
 
 
 
 
251
  except Exception as e:
252
  print(f"Error in main: {str(e)}")
253
  print(traceback.format_exc())
 
89
  C. ํŠน์žฅ์ 
90
  D. ์ ์šฉ ๋Œ€์ƒ ๋ฐ ํƒ€๊ฒŸ
91
  E. ๊ธฐ๋Œ€ํšจ๊ณผ
92
+ ๊ธฐ์กด ๋ฐ ์œ ์‚ฌ ํ”„๋กœ์ ํŠธ์™€ ๋น„๊ตํ•˜์—ฌ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”. Markdown ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”."""
93
  user_message = f"๋‹ค์Œ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
94
 
95
  messages = [
 
104
  return f"๋ถ„์„ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
105
 
106
  def explain_usage(app_content: str) -> str:
107
+ system_message = "๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋ฒ•์„ ์ƒ์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”. Markdown ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”."
108
  user_message = f"๋‹ค์Œ Python ์ฝ”๋“œ์˜ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
109
 
110
  messages = [
 
118
  except Exception as e:
119
  return f"์‚ฌ์šฉ๋ฒ• ์„ค๋ช… ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
120
 
121
+ def analyze_space(url: str, progress=gr.Progress()):
122
  try:
123
  space_id = url.split('spaces/')[-1]
124
 
125
+ progress(0.1, desc="ํŒŒ์ผ ๊ตฌ์กฐ ๋ถ„์„ ์ค‘...")
126
+ tree_structure = get_space_structure(space_id)
127
+ tree_view = format_tree_structure(tree_structure)
128
+
129
+ progress(0.3, desc="app.py ๋‚ด์šฉ ๊ฐ€์ ธ์˜ค๋Š” ์ค‘...")
130
  app_content = get_file_content(space_id, "app.py")
131
+
132
+ progress(0.4, desc="์ฝ”๋“œ ์š”์•ฝ ์ค‘...")
133
  summary = summarize_code(app_content)
134
+
135
+ progress(0.6, desc="์ฝ”๋“œ ๋ถ„์„ ์ค‘...")
136
  analysis = analyze_code(app_content)
 
137
 
138
+ progress(0.8, desc="์‚ฌ์šฉ๋ฒ• ์„ค๋ช… ์ƒ์„ฑ ์ค‘...")
139
+ usage = explain_usage(app_content)
140
 
141
+ progress(1.0, desc="์™„๋ฃŒ")
142
  return summary, analysis, usage, app_content, tree_view, tree_structure, space_id
143
  except Exception as e:
144
  print(f"Error in analyze_space: {str(e)}")
 
156
  margin-bottom: 20px;
157
  }
158
  .scroll-lock {
159
+ overflow-y: auto !important;
160
+ max-height: calc((100vh - 200px) / 5) !important;
 
161
  }
162
  .full-height {
163
  height: calc(100vh - 200px) !important;
164
+ overflow-y: auto !important;
165
  }
166
  """
167
 
 
174
  analyze_button = gr.Button("๋ถ„์„")
175
 
176
  with gr.Group(elem_classes="output-group scroll-lock"):
177
+ summary_output = gr.Markdown(label="์š”์•ฝ (3์ค„ ์ด๋‚ด)")
178
 
179
  with gr.Group(elem_classes="output-group scroll-lock"):
180
+ analysis_output = gr.Markdown(label="๋ถ„์„")
181
 
182
  with gr.Group(elem_classes="output-group scroll-lock"):
183
+ usage_output = gr.Markdown(label="์‚ฌ์šฉ๋ฒ•")
184
 
185
  with gr.Group(elem_classes="output-group scroll-lock"):
186
  tree_view_output = gr.Textbox(label="ํŒŒ์ผ ๊ตฌ์กฐ (Tree View)", lines=20)
187
 
188
+ with gr.Group(elem_classes="output-group scroll-lock"):
189
+ file_buttons = gr.Dataframe(
190
+ headers=["ํŒŒ์ผ ์ด๋ฆ„", "์—ด๊ธฐ"],
191
+ datatype=["str", "html"],
192
+ col_count=(2, "fixed"),
193
+ label="ํŒŒ์ผ ๋ฆฌ์ŠคํŠธ"
194
+ )
195
 
196
  with gr.Column(scale=4): # ์˜ค๋ฅธ์ชฝ 40%
197
+ with gr.Group(elem_classes="output-group full-height"):
198
  code_tabs = gr.Tabs()
199
  with code_tabs:
200
  app_py_tab = gr.TabItem("app.py")
 
257
  try:
258
  demo = create_ui()
259
  demo.queue()
260
+ demo.launch(js="""
261
+ function openFile(path, spaceId) {
262
+ const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
263
+ const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
264
+ if (filePathInput && spaceIdInput) {
265
+ filePathInput.value = path;
266
+ spaceIdInput.value = spaceId;
267
+ filePathInput.dispatchEvent(new Event('change'));
268
+ }
269
+ }
270
+ """)
271
  except Exception as e:
272
  print(f"Error in main: {str(e)}")
273
  print(traceback.format_exc())