Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
131 |
-
|
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:
|
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.
|
169 |
|
170 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
171 |
-
analysis_output = gr.
|
172 |
|
173 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
174 |
-
usage_output = gr.
|
175 |
|
176 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
177 |
tree_view_output = gr.Textbox(label="ํ์ผ ๊ตฌ์กฐ (Tree View)", lines=20)
|
178 |
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
185 |
|
186 |
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
187 |
-
with gr.Group(elem_classes="output-group
|
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())
|