Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -192,17 +192,15 @@ def create_ui():
|
|
192 |
height: calc(100vh - 200px) !important;
|
193 |
overflow-y: auto !important;
|
194 |
}
|
|
|
|
|
|
|
195 |
"""
|
196 |
|
197 |
js = """
|
198 |
function openFile(path, spaceId) {
|
199 |
-
const
|
200 |
-
|
201 |
-
if (filePathInput && spaceIdInput) {
|
202 |
-
filePathInput.value = path;
|
203 |
-
spaceIdInput.value = spaceId;
|
204 |
-
filePathInput.dispatchEvent(new Event('change'));
|
205 |
-
}
|
206 |
}
|
207 |
"""
|
208 |
|
@@ -233,11 +231,14 @@ def create_ui():
|
|
233 |
|
234 |
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
235 |
with gr.Group(elem_classes="output-group full-height"):
|
236 |
-
code_tabs = gr.Tabs()
|
237 |
with code_tabs:
|
238 |
app_py_tab = gr.TabItem("app.py")
|
239 |
with app_py_tab:
|
240 |
app_py_content = gr.Code(language="python", label="app.py", lines=30)
|
|
|
|
|
|
|
241 |
|
242 |
with gr.TabItem("AI ์ฝ๋ฉ"):
|
243 |
chatbot = gr.Chatbot()
|
@@ -249,6 +250,9 @@ def create_ui():
|
|
249 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
250 |
|
251 |
examples = [
|
|
|
|
|
|
|
252 |
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
253 |
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
254 |
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
@@ -285,13 +289,14 @@ def create_ui():
|
|
285 |
files = get_files(tree_structure)
|
286 |
buttons_html = "<div style='display: flex; flex-direction: column;'>"
|
287 |
for file in files:
|
288 |
-
buttons_html += f"<button onclick=\"openFile('{file['path']}', '{space_id}')\" style='margin: 5px 0; padding: 5px;'>{file['path']}</button>"
|
289 |
buttons_html += "</div>"
|
290 |
return buttons_html
|
291 |
|
292 |
def open_file(file_path: str, space_id: str):
|
293 |
content = get_file_content(space_id, file_path)
|
294 |
-
|
|
|
295 |
|
296 |
analyze_button.click(
|
297 |
analyze_space,
|
@@ -301,6 +306,10 @@ def create_ui():
|
|
301 |
update_file_buttons,
|
302 |
inputs=[tree_structure_state, space_id_state],
|
303 |
outputs=[file_buttons]
|
|
|
|
|
|
|
|
|
304 |
)
|
305 |
|
306 |
file_path_input = gr.Textbox(visible=False)
|
@@ -318,6 +327,23 @@ def create_ui():
|
|
318 |
# JavaScript ์ฝ๋๋ฅผ HTML์ ์ง์ ์ฝ์
|
319 |
gr.HTML(f"<script>{js}</script>")
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
return demo
|
322 |
|
323 |
except Exception as e:
|
@@ -332,4 +358,4 @@ if __name__ == "__main__":
|
|
332 |
demo.launch()
|
333 |
except Exception as e:
|
334 |
print(f"Error in main: {str(e)}")
|
335 |
-
print(traceback.format_exc())
|
|
|
192 |
height: calc(100vh - 200px) !important;
|
193 |
overflow-y: auto !important;
|
194 |
}
|
195 |
+
.tabs-style {
|
196 |
+
background-color: #ffff00;
|
197 |
+
}
|
198 |
"""
|
199 |
|
200 |
js = """
|
201 |
function openFile(path, spaceId) {
|
202 |
+
const event = new CustomEvent('open-file', { detail: { path, spaceId } });
|
203 |
+
window.dispatchEvent(event);
|
|
|
|
|
|
|
|
|
|
|
204 |
}
|
205 |
"""
|
206 |
|
|
|
231 |
|
232 |
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
233 |
with gr.Group(elem_classes="output-group full-height"):
|
234 |
+
code_tabs = gr.Tabs(elem_classes="tabs-style")
|
235 |
with code_tabs:
|
236 |
app_py_tab = gr.TabItem("app.py")
|
237 |
with app_py_tab:
|
238 |
app_py_content = gr.Code(language="python", label="app.py", lines=30)
|
239 |
+
requirements_tab = gr.TabItem("requirements.txt")
|
240 |
+
with requirements_tab:
|
241 |
+
requirements_content = gr.Code(language="text", label="requirements.txt", lines=30)
|
242 |
|
243 |
with gr.TabItem("AI ์ฝ๋ฉ"):
|
244 |
chatbot = gr.Chatbot()
|
|
|
250 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
251 |
|
252 |
examples = [
|
253 |
+
["ํจ์
์ฝ๋ ์คํ"],
|
254 |
+
["UHD ์ด๋ฏธ์ง ์ฝ๋ ์คํ"],
|
255 |
+
["MixGEN ์ฝ๋ ์คํ"],
|
256 |
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
257 |
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
258 |
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
|
|
289 |
files = get_files(tree_structure)
|
290 |
buttons_html = "<div style='display: flex; flex-direction: column;'>"
|
291 |
for file in files:
|
292 |
+
buttons_html += f"<button onclick=\"openFile('{file['path']}', '{space_id}')\" style='margin: 5px 0; padding: 5px; cursor: pointer;'>{file['path']}</button>"
|
293 |
buttons_html += "</div>"
|
294 |
return buttons_html
|
295 |
|
296 |
def open_file(file_path: str, space_id: str):
|
297 |
content = get_file_content(space_id, file_path)
|
298 |
+
file_name = file_path.split('/')[-1]
|
299 |
+
return gr.Tabs.update(selected=file_name), gr.Code(value=content, language="python" if file_name.endswith('.py') else "text", label=file_name, lines=30)
|
300 |
|
301 |
analyze_button.click(
|
302 |
analyze_space,
|
|
|
306 |
update_file_buttons,
|
307 |
inputs=[tree_structure_state, space_id_state],
|
308 |
outputs=[file_buttons]
|
309 |
+
).then(
|
310 |
+
lambda space_id: get_file_content(space_id, "requirements.txt"),
|
311 |
+
inputs=[space_id_state],
|
312 |
+
outputs=[requirements_content]
|
313 |
)
|
314 |
|
315 |
file_path_input = gr.Textbox(visible=False)
|
|
|
327 |
# JavaScript ์ฝ๋๋ฅผ HTML์ ์ง์ ์ฝ์
|
328 |
gr.HTML(f"<script>{js}</script>")
|
329 |
|
330 |
+
# ํ์ผ ์ด๊ธฐ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ถ๊ฐ
|
331 |
+
demo.load(None, None, None, _js="""
|
332 |
+
() => {
|
333 |
+
function handleOpenFile(event) {
|
334 |
+
const { path, spaceId } = event.detail;
|
335 |
+
const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
|
336 |
+
const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
|
337 |
+
if (filePathInput && spaceIdInput) {
|
338 |
+
filePathInput.value = path;
|
339 |
+
spaceIdInput.value = spaceId;
|
340 |
+
filePathInput.dispatchEvent(new Event('change'));
|
341 |
+
}
|
342 |
+
}
|
343 |
+
window.addEventListener('open-file', handleOpenFile);
|
344 |
+
}
|
345 |
+
""")
|
346 |
+
|
347 |
return demo
|
348 |
|
349 |
except Exception as e:
|
|
|
358 |
demo.launch()
|
359 |
except Exception as e:
|
360 |
print(f"Error in main: {str(e)}")
|
361 |
+
print(traceback.format_exc())
|