Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -86,7 +86,6 @@ def summarize_code(app_content: str):
|
|
86 |
except Exception as e:
|
87 |
return f"μμ½ μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
88 |
|
89 |
-
|
90 |
def analyze_code(app_content: str):
|
91 |
system_message = """λΉμ μ Python μ½λλ₯Ό λΆμνλ AI μ‘°μμ
λλ€. μ£Όμ΄μ§ μ½λλ₯Ό λΆμνμ¬ λ€μ νλͺ©μ λν΄ μ€λͺ
ν΄μ£ΌμΈμ:
|
92 |
A. λ°°κ²½ λ° νμμ±
|
@@ -160,8 +159,6 @@ def respond(message: str, chat_history: List[Dict[str, str]], system_message: st
|
|
160 |
except Exception as e:
|
161 |
return f"μλ΅ μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
162 |
|
163 |
-
|
164 |
-
|
165 |
def create_ui():
|
166 |
try:
|
167 |
css = """
|
@@ -247,9 +244,7 @@ def create_ui():
|
|
247 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
248 |
|
249 |
examples = [
|
250 |
-
|
251 |
-
["UHD μ΄λ―Έμ§ μ½λ μ€ν"],
|
252 |
-
["MixGEN μ½λ μ€ν"],
|
253 |
["μμΈν μ¬μ© λ°©λ²μ λ§μΉ νλ©΄μ 보면μ μ€λͺ
νλ―μ΄ 4000 ν ν° μ΄μ μμΈν μ€λͺ
νλΌ"],
|
254 |
["FAQ 20건μ μμΈνκ² μμ±νλΌ. 4000ν ν° μ΄μ μ¬μ©νλΌ."],
|
255 |
["μ¬μ© λ°©λ²κ³Ό μ°¨λ³μ , νΉμ§, κ°μ μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μ νλΈ μμ μ€ν¬λ¦½νΈ ννλ‘ μμ±νλΌ"],
|
@@ -268,7 +263,87 @@ def create_ui():
|
|
268 |
|
269 |
msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
|
270 |
|
271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
return demo
|
274 |
|
@@ -288,4 +363,4 @@ if __name__ == "__main__":
|
|
288 |
)
|
289 |
except Exception as e:
|
290 |
print(f"Error in main: {str(e)}")
|
291 |
-
print(traceback.format_exc())
|
|
|
86 |
except Exception as e:
|
87 |
return f"μμ½ μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
88 |
|
|
|
89 |
def analyze_code(app_content: str):
|
90 |
system_message = """λΉμ μ Python μ½λλ₯Ό λΆμνλ AI μ‘°μμ
λλ€. μ£Όμ΄μ§ μ½λλ₯Ό λΆμνμ¬ λ€μ νλͺ©μ λν΄ μ€λͺ
ν΄μ£ΌμΈμ:
|
91 |
A. λ°°κ²½ λ° νμμ±
|
|
|
159 |
except Exception as e:
|
160 |
return f"μλ΅ μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
161 |
|
|
|
|
|
162 |
def create_ui():
|
163 |
try:
|
164 |
css = """
|
|
|
244 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
245 |
|
246 |
examples = [
|
247 |
+
|
|
|
|
|
248 |
["μμΈν μ¬μ© λ°©λ²μ λ§μΉ νλ©΄μ 보면μ μ€λͺ
νλ―μ΄ 4000 ν ν° μ΄μ μμΈν μ€λͺ
νλΌ"],
|
249 |
["FAQ 20건μ μμΈνκ² μμ±νλΌ. 4000ν ν° μ΄μ μ¬μ©νλΌ."],
|
250 |
["μ¬μ© λ°©λ²κ³Ό μ°¨λ³μ , νΉμ§, κ°μ μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μ νλΈ μμ μ€ν¬λ¦½νΈ ννλ‘ μμ±νλΌ"],
|
|
|
263 |
|
264 |
msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
|
265 |
|
266 |
+
space_id_state = gr.State()
|
267 |
+
tree_structure_state = gr.State()
|
268 |
+
|
269 |
+
def update_file_buttons(tree_structure, space_id):
|
270 |
+
if tree_structure is None:
|
271 |
+
return ""
|
272 |
+
|
273 |
+
def get_files(node):
|
274 |
+
|
275 |
+
files = []
|
276 |
+
if node["type"] == "file":
|
277 |
+
files.append(node)
|
278 |
+
elif node["type"] == "directory":
|
279 |
+
for child in node.get("children", []):
|
280 |
+
files.extend(get_files(child))
|
281 |
+
return files
|
282 |
+
|
283 |
+
files = get_files(tree_structure)
|
284 |
+
buttons_html = "<div style='display: flex; flex-direction: column;'>"
|
285 |
+
for file in files:
|
286 |
+
buttons_html += f"<button class='file-button' onclick='openFile(\"{file['path']}\", \"{space_id}\")'>{file['path']}</button>"
|
287 |
+
buttons_html += "</div>"
|
288 |
+
return buttons_html
|
289 |
+
|
290 |
+
def open_file(file_path: str, space_id: str):
|
291 |
+
content = get_file_content(space_id, file_path)
|
292 |
+
file_name = file_path.split('/')[-1]
|
293 |
+
if file_name == "requirements.txt":
|
294 |
+
return gr.Tabs.update(selected="requirements.txt"), gr.Textbox.update(value=content, label=file_name)
|
295 |
+
else:
|
296 |
+
return gr.Tabs.update(selected=file_name), gr.Code.update(value=content, language="python" if file_name.endswith('.py') else "plaintext", label=file_name)
|
297 |
+
|
298 |
+
analyze_button.click(
|
299 |
+
analyze_space,
|
300 |
+
inputs=[url_input],
|
301 |
+
outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state]
|
302 |
+
).then(
|
303 |
+
update_file_buttons,
|
304 |
+
inputs=[tree_structure_state, space_id_state],
|
305 |
+
outputs=[file_buttons]
|
306 |
+
).then(
|
307 |
+
summarize_code,
|
308 |
+
inputs=[app_py_content],
|
309 |
+
outputs=[summary_output]
|
310 |
+
).then(
|
311 |
+
analyze_code,
|
312 |
+
inputs=[app_py_content],
|
313 |
+
outputs=[analysis_output]
|
314 |
+
).then(
|
315 |
+
explain_usage,
|
316 |
+
inputs=[app_py_content],
|
317 |
+
outputs=[usage_output]
|
318 |
+
).then(
|
319 |
+
lambda space_id: get_file_content(space_id, "requirements.txt"),
|
320 |
+
inputs=[space_id_state],
|
321 |
+
outputs=[requirements_content]
|
322 |
+
)
|
323 |
+
|
324 |
+
file_path_input = gr.Textbox(visible=False)
|
325 |
+
space_id_input = gr.Textbox(visible=False)
|
326 |
+
|
327 |
+
file_path_input.change(
|
328 |
+
open_file,
|
329 |
+
inputs=[file_path_input, space_id_input],
|
330 |
+
outputs=[code_tabs, code_tabs]
|
331 |
+
)
|
332 |
+
|
333 |
+
# JavaScript μ½λλ₯Ό HTMLμ μ§μ μ½μ
|
334 |
+
gr.HTML("""
|
335 |
+
<script>
|
336 |
+
function openFile(path, spaceId) {
|
337 |
+
const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
|
338 |
+
const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
|
339 |
+
if (filePathInput && spaceIdInput) {
|
340 |
+
filePathInput.value = path;
|
341 |
+
spaceIdInput.value = spaceId;
|
342 |
+
filePathInput.dispatchEvent(new Event('change'));
|
343 |
+
}
|
344 |
+
}
|
345 |
+
</script>
|
346 |
+
""")
|
347 |
|
348 |
return demo
|
349 |
|
|
|
363 |
)
|
364 |
except Exception as e:
|
365 |
print(f"Error in main: {str(e)}")
|
366 |
+
print(traceback.format_exc())
|