Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -122,6 +122,8 @@ def explain_usage(app_content: str):
|
|
122 |
except Exception as e:
|
123 |
return f"μ¬μ©λ² μ€λͺ
μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
124 |
|
|
|
|
|
125 |
def analyze_space(url: str, progress=gr.Progress()):
|
126 |
try:
|
127 |
space_id = url.split('spaces/')[-1]
|
@@ -139,12 +141,24 @@ def analyze_space(url: str, progress=gr.Progress()):
|
|
139 |
progress(0.3, desc="app.py λ΄μ© κ°μ Έμ€λ μ€...")
|
140 |
app_content = get_file_content(space_id, "app.py")
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
progress(1.0, desc="μλ£")
|
143 |
-
return app_content, tree_view, tree_structure, space_id
|
144 |
except Exception as e:
|
145 |
print(f"Error in analyze_space: {str(e)}")
|
146 |
print(traceback.format_exc())
|
147 |
-
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "", None, ""
|
|
|
|
|
|
|
148 |
|
149 |
def respond(message: str, chat_history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float):
|
150 |
messages = [{"role": "system", "content": system_message}]
|
@@ -201,7 +215,7 @@ def create_ui():
|
|
201 |
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
202 |
gr.Markdown("# HuggingFace Space Analyzer")
|
203 |
|
204 |
-
with gr.Tabs() as tabs:
|
205 |
with gr.TabItem("λΆμ"):
|
206 |
with gr.Row():
|
207 |
with gr.Column(scale=6): # μΌμͺ½ 60%
|
@@ -225,7 +239,7 @@ def create_ui():
|
|
225 |
|
226 |
with gr.Column(scale=4): # μ€λ₯Έμͺ½ 40%
|
227 |
with gr.Group(elem_classes="output-group full-height"):
|
228 |
-
code_tabs = gr.Tabs()
|
229 |
with code_tabs:
|
230 |
app_py_tab = gr.TabItem("app.py")
|
231 |
with app_py_tab:
|
@@ -244,7 +258,6 @@ def create_ui():
|
|
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 ν ν° μ΄μ μ νλΈ μμ μ€ν¬λ¦½νΈ ννλ‘ μμ±νλΌ"],
|
@@ -271,7 +284,6 @@ def create_ui():
|
|
271 |
return ""
|
272 |
|
273 |
def get_files(node):
|
274 |
-
|
275 |
files = []
|
276 |
if node["type"] == "file":
|
277 |
files.append(node)
|
@@ -298,23 +310,11 @@ def create_ui():
|
|
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],
|
@@ -336,31 +336,4 @@ def create_ui():
|
|
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
|
340 |
-
filePathInput.value = path;
|
341 |
-
spaceIdInput.value = spaceId;
|
342 |
-
filePathInput.dispatchEvent(new Event('change'));
|
343 |
-
}
|
344 |
-
}
|
345 |
-
</script>
|
346 |
-
""")
|
347 |
-
|
348 |
-
return demo
|
349 |
-
|
350 |
-
except Exception as e:
|
351 |
-
print(f"Error in create_ui: {str(e)}")
|
352 |
-
print(traceback.format_exc())
|
353 |
-
raise
|
354 |
-
|
355 |
-
if __name__ == "__main__":
|
356 |
-
try:
|
357 |
-
demo = create_ui()
|
358 |
-
demo.queue()
|
359 |
-
demo.launch(
|
360 |
-
share=False,
|
361 |
-
debug=True,
|
362 |
-
show_api=False
|
363 |
-
)
|
364 |
-
except Exception as e:
|
365 |
-
print(f"Error in main: {str(e)}")
|
366 |
-
print(traceback.format_exc())
|
|
|
122 |
except Exception as e:
|
123 |
return f"μ¬μ©λ² μ€λͺ
μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
124 |
|
125 |
+
|
126 |
+
|
127 |
def analyze_space(url: str, progress=gr.Progress()):
|
128 |
try:
|
129 |
space_id = url.split('spaces/')[-1]
|
|
|
141 |
progress(0.3, desc="app.py λ΄μ© κ°μ Έμ€λ μ€...")
|
142 |
app_content = get_file_content(space_id, "app.py")
|
143 |
|
144 |
+
progress(0.5, desc="μ½λ μμ½ μ€...")
|
145 |
+
summary = summarize_code(app_content)
|
146 |
+
|
147 |
+
progress(0.7, desc="μ½λ λΆμ μ€...")
|
148 |
+
analysis = analyze_code(app_content)
|
149 |
+
|
150 |
+
progress(0.9, desc="μ¬μ©λ² μ€λͺ
μμ± μ€...")
|
151 |
+
usage = explain_usage(app_content)
|
152 |
+
|
153 |
progress(1.0, desc="μλ£")
|
154 |
+
return app_content, tree_view, tree_structure, space_id, summary, analysis, usage
|
155 |
except Exception as e:
|
156 |
print(f"Error in analyze_space: {str(e)}")
|
157 |
print(traceback.format_exc())
|
158 |
+
return f"μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "", None, "", "", "", ""
|
159 |
+
|
160 |
+
|
161 |
+
|
162 |
|
163 |
def respond(message: str, chat_history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float):
|
164 |
messages = [{"role": "system", "content": system_message}]
|
|
|
215 |
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
216 |
gr.Markdown("# HuggingFace Space Analyzer")
|
217 |
|
218 |
+
with gr.Tabs(elem_classes="main-tabs") as tabs:
|
219 |
with gr.TabItem("λΆμ"):
|
220 |
with gr.Row():
|
221 |
with gr.Column(scale=6): # μΌμͺ½ 60%
|
|
|
239 |
|
240 |
with gr.Column(scale=4): # μ€λ₯Έμͺ½ 40%
|
241 |
with gr.Group(elem_classes="output-group full-height"):
|
242 |
+
code_tabs = gr.Tabs(elem_classes="code-tabs")
|
243 |
with code_tabs:
|
244 |
app_py_tab = gr.TabItem("app.py")
|
245 |
with app_py_tab:
|
|
|
258 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
259 |
|
260 |
examples = [
|
|
|
261 |
["μμΈν μ¬μ© λ°©λ²μ λ§μΉ νλ©΄μ 보면μ μ€λͺ
νλ―μ΄ 4000 ν ν° μ΄μ μμΈν μ€λͺ
νλΌ"],
|
262 |
["FAQ 20건μ μμΈνκ² μμ±νλΌ. 4000ν ν° μ΄μ μ¬μ©νλΌ."],
|
263 |
["μ¬μ© λ°©λ²κ³Ό μ°¨λ³μ , νΉμ§, κ°μ μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μ νλΈ μμ μ€ν¬λ¦½νΈ ννλ‘ μμ±νλΌ"],
|
|
|
284 |
return ""
|
285 |
|
286 |
def get_files(node):
|
|
|
287 |
files = []
|
288 |
if node["type"] == "file":
|
289 |
files.append(node)
|
|
|
310 |
analyze_button.click(
|
311 |
analyze_space,
|
312 |
inputs=[url_input],
|
313 |
+
outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state, summary_output, analysis_output, usage_output]
|
314 |
).then(
|
315 |
update_file_buttons,
|
316 |
inputs=[tree_structure_state, space_id_state],
|
317 |
outputs=[file_buttons]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
).then(
|
319 |
lambda space_id: get_file_content(space_id, "requirements.txt"),
|
320 |
inputs=[space_id_state],
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|