Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -123,27 +123,13 @@ def explain_usage(app_content: str):
|
|
123 |
return f"μ¬μ©λ² μ€λͺ
μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
124 |
|
125 |
def adjust_lines_for_code(code_content: str, min_lines: int = 10, max_lines: int = 100) -> int:
|
126 |
-
"""
|
127 |
-
μ½λ λ΄μ©μ λ°λΌ lines μλ₯Ό λμ μΌλ‘ μ‘°μ ν©λλ€.
|
128 |
-
|
129 |
-
Parameters:
|
130 |
-
- code_content (str): μ½λ ν
μ€νΈ λ΄μ©
|
131 |
-
- min_lines (int): μ΅μ lines μ
|
132 |
-
- max_lines (int): μ΅λ lines μ
|
133 |
-
|
134 |
-
Returns:
|
135 |
-
- int: μ€μ λ lines μ
|
136 |
-
"""
|
137 |
-
# μ½λμ μ€ μ κ³μ°
|
138 |
num_lines = len(code_content.split('\n'))
|
139 |
-
# μ€ μκ° min_linesλ³΄λ€ μ λ€λ©΄ min_lines μ¬μ©, max_linesλ³΄λ€ ν¬λ©΄ max_lines μ¬μ©
|
140 |
return min(max(num_lines, min_lines), max_lines)
|
141 |
|
142 |
def analyze_space(url: str, progress=gr.Progress()):
|
143 |
try:
|
144 |
space_id = url.split('spaces/')[-1]
|
145 |
|
146 |
-
# Space ID μ ν¨μ± κ²μ¬ μμ
|
147 |
if not re.match(r'^[\w.-]+/[\w.-]+$', space_id):
|
148 |
raise ValueError(f"Invalid Space ID format: {space_id}")
|
149 |
|
@@ -165,7 +151,6 @@ def analyze_space(url: str, progress=gr.Progress()):
|
|
165 |
progress(0.9, desc="μ¬μ©λ² μ€λͺ
μμ± μ€...")
|
166 |
usage = explain_usage(app_content)
|
167 |
|
168 |
-
# μ€ μ κ³μ°νμ¬ lines μ€μ
|
169 |
app_py_lines = adjust_lines_for_code(app_content)
|
170 |
|
171 |
progress(1.0, desc="μλ£")
|
@@ -252,23 +237,7 @@ def create_ui():
|
|
252 |
color: #2c3e50 !important;
|
253 |
background-color: #ecf0f1 !important;
|
254 |
}
|
255 |
-
.copy-button {
|
256 |
-
padding: 5px 10px;
|
257 |
-
background-color: #3498db;
|
258 |
-
color: white;
|
259 |
-
border: none;
|
260 |
-
border-radius: 3px;
|
261 |
-
cursor: pointer;
|
262 |
-
font-size: 12px;
|
263 |
-
}
|
264 |
-
.copy-button:hover {
|
265 |
-
background-color: #2980b9;
|
266 |
-
}
|
267 |
"""
|
268 |
-
|
269 |
-
|
270 |
-
def copy_text(text):
|
271 |
-
return text, f"'{text[:20]}...' 볡μ¬λ¨"
|
272 |
|
273 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
274 |
gr.Markdown("# Mouse: HuggingFace")
|
@@ -281,30 +250,16 @@ def create_ui():
|
|
281 |
analyze_button = gr.Button("λΆμ")
|
282 |
|
283 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
284 |
-
|
285 |
-
summary_output = gr.Markdown(label="μμ½ (3μ€ μ΄λ΄)")
|
286 |
-
copy_summary = gr.Button("볡μ¬", elem_classes="copy-button")
|
287 |
-
copy_summary_output = gr.Textbox(label="볡μ¬λ λ΄μ©", visible=False)
|
288 |
|
289 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
290 |
-
|
291 |
-
analysis_output = gr.Markdown(label="λΆμ")
|
292 |
-
copy_analysis = gr.Button("볡μ¬", elem_classes="copy-button")
|
293 |
-
copy_analysis_output = gr.Textbox(label="볡μ¬λ λ΄μ©", visible=False)
|
294 |
|
295 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
296 |
-
|
297 |
-
usage_output = gr.Markdown(label="μ¬μ©λ²")
|
298 |
-
copy_usage = gr.Button("볡μ¬", elem_classes="copy-button")
|
299 |
-
copy_usage_output = gr.Textbox(label="볡μ¬λ λ΄μ©", visible=False)
|
300 |
|
301 |
with gr.Group(elem_classes="output-group tree-view-scroll"):
|
302 |
-
|
303 |
-
tree_view_output = gr.Textbox(label="νμΌ κ΅¬μ‘° (Tree View)", lines=30)
|
304 |
-
copy_tree = gr.Button("볡μ¬", elem_classes="copy-button")
|
305 |
-
copy_tree_output = gr.Textbox(label="볡μ¬λ λ΄μ©", visible=False)
|
306 |
-
|
307 |
-
|
308 |
|
309 |
with gr.Column(scale=4): # μ€λ₯Έμͺ½ 40%
|
310 |
with gr.Group(elem_classes="output-group full-height"):
|
@@ -312,30 +267,24 @@ def create_ui():
|
|
312 |
with code_tabs:
|
313 |
app_py_tab = gr.TabItem("app.py")
|
314 |
with app_py_tab:
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
)
|
322 |
-
copy_app_py = gr.Button("볡μ¬", elem_classes="copy-button")
|
323 |
requirements_tab = gr.TabItem("requirements.txt")
|
324 |
with requirements_tab:
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
)
|
331 |
-
copy_requirements = gr.Button("볡μ¬", elem_classes="copy-button")
|
332 |
-
|
333 |
|
334 |
with gr.TabItem("AI μ½λ©"):
|
335 |
chatbot = gr.Chatbot(label="λν", type='messages')
|
336 |
msg = gr.Textbox(label="λ©μμ§")
|
337 |
|
338 |
-
# μ¨κ²¨μ§ μνλ‘ νλΌλ―Έν° μ€μ
|
339 |
max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
|
340 |
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
|
341 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
|
@@ -372,18 +321,7 @@ def create_ui():
|
|
372 |
inputs=[space_id_state],
|
373 |
outputs=[requirements_content]
|
374 |
)
|
375 |
-
# λ³΅μ¬ κΈ°λ₯ μ°κ²°
|
376 |
-
copy_summary.click(copy_text, inputs=[summary_output], outputs=[copy_summary_output, gr.Textbox(label="μν")])
|
377 |
-
copy_analysis.click(copy_text, inputs=[analysis_output], outputs=[copy_analysis_output, gr.Textbox(label="μν")])
|
378 |
-
copy_usage.click(copy_text, inputs=[usage_output], outputs=[copy_usage_output, gr.Textbox(label="μν")])
|
379 |
-
copy_tree.click(copy_text, inputs=[tree_view_output], outputs=[copy_tree_output, gr.Textbox(label="μν")])
|
380 |
-
copy_app_py.click(copy_text, inputs=[app_py_content], outputs=[gr.Textbox(label="볡μ¬λ λ΄μ©", visible=False), gr.Textbox(label="μν")])
|
381 |
-
copy_requirements.click(copy_text, inputs=[requirements_content], outputs=[gr.Textbox(label="볡μ¬λ λ΄μ©", visible=False), gr.Textbox(label="μν")])
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
|
386 |
-
# lines μλ₯Ό λμ μΌλ‘ μ€μ
|
387 |
app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
|
388 |
|
389 |
return demo
|
|
|
123 |
return f"μ¬μ©λ² μ€λͺ
μμ± μ€ μ€λ₯ λ°μ: {str(e)}"
|
124 |
|
125 |
def adjust_lines_for_code(code_content: str, min_lines: int = 10, max_lines: int = 100) -> int:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
num_lines = len(code_content.split('\n'))
|
|
|
127 |
return min(max(num_lines, min_lines), max_lines)
|
128 |
|
129 |
def analyze_space(url: str, progress=gr.Progress()):
|
130 |
try:
|
131 |
space_id = url.split('spaces/')[-1]
|
132 |
|
|
|
133 |
if not re.match(r'^[\w.-]+/[\w.-]+$', space_id):
|
134 |
raise ValueError(f"Invalid Space ID format: {space_id}")
|
135 |
|
|
|
151 |
progress(0.9, desc="μ¬μ©λ² μ€λͺ
μμ± μ€...")
|
152 |
usage = explain_usage(app_content)
|
153 |
|
|
|
154 |
app_py_lines = adjust_lines_for_code(app_content)
|
155 |
|
156 |
progress(1.0, desc="μλ£")
|
|
|
237 |
color: #2c3e50 !important;
|
238 |
background-color: #ecf0f1 !important;
|
239 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
"""
|
|
|
|
|
|
|
|
|
241 |
|
242 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
243 |
gr.Markdown("# Mouse: HuggingFace")
|
|
|
250 |
analyze_button = gr.Button("λΆμ")
|
251 |
|
252 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
253 |
+
summary_output = gr.Markdown(label="μμ½ (3μ€ μ΄λ΄)")
|
|
|
|
|
|
|
254 |
|
255 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
256 |
+
analysis_output = gr.Markdown(label="λΆμ")
|
|
|
|
|
|
|
257 |
|
258 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
259 |
+
usage_output = gr.Markdown(label="μ¬μ©λ²")
|
|
|
|
|
|
|
260 |
|
261 |
with gr.Group(elem_classes="output-group tree-view-scroll"):
|
262 |
+
tree_view_output = gr.Textbox(label="νμΌ κ΅¬μ‘° (Tree View)", lines=30)
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
with gr.Column(scale=4): # μ€λ₯Έμͺ½ 40%
|
265 |
with gr.Group(elem_classes="output-group full-height"):
|
|
|
267 |
with code_tabs:
|
268 |
app_py_tab = gr.TabItem("app.py")
|
269 |
with app_py_tab:
|
270 |
+
app_py_content = gr.Code(
|
271 |
+
language="python",
|
272 |
+
label="app.py",
|
273 |
+
lines=200,
|
274 |
+
elem_classes="full-height code-box"
|
275 |
+
)
|
|
|
|
|
276 |
requirements_tab = gr.TabItem("requirements.txt")
|
277 |
with requirements_tab:
|
278 |
+
requirements_content = gr.Textbox(
|
279 |
+
label="requirements.txt",
|
280 |
+
lines=200,
|
281 |
+
elem_classes="full-height code-box"
|
282 |
+
)
|
|
|
|
|
|
|
283 |
|
284 |
with gr.TabItem("AI μ½λ©"):
|
285 |
chatbot = gr.Chatbot(label="λν", type='messages')
|
286 |
msg = gr.Textbox(label="λ©μμ§")
|
287 |
|
|
|
288 |
max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens", visible=False)
|
289 |
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature", visible=False)
|
290 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P", visible=False)
|
|
|
321 |
inputs=[space_id_state],
|
322 |
outputs=[requirements_content]
|
323 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
|
|
325 |
app_py_content.change(lambda lines: gr.update(lines=lines), inputs=[app_py_content_lines], outputs=[app_py_content])
|
326 |
|
327 |
return demo
|