Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -122,8 +122,6 @@ def explain_usage(app_content: str):
|
|
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]
|
@@ -157,16 +155,13 @@ def analyze_space(url: str, progress=gr.Progress()):
|
|
157 |
print(traceback.format_exc())
|
158 |
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", None, "", "", "", ""
|
159 |
|
160 |
-
|
161 |
def respond(message: str, chat_history: List[Dict[str, str]], max_tokens: int, temperature: float, top_p: float) -> str:
|
162 |
system_message = """๋น์ ์ ํ๊น
ํ์ด์ค์ ํนํ๋ AI ์ฝ๋ฉ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ์ง๋ฌธ์ ์น์ ํ๊ณ ์์ธํ๊ฒ ๋ต๋ณํด์ฃผ์ธ์.
|
163 |
Gradio ํน์ฑ์ ์ ํํ ์ธ์ํ๊ณ Requirements.txt ๋๋ฝ์์ด ์ฝ๋ฉ๊ณผ ์ค๋ฅ๋ฅผ ํด๊ฒฐํด์ผ ํฉ๋๋ค.
|
164 |
ํญ์ ์ ํํ๊ณ ์ ์ฉํ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋๋ก ๋
ธ๋ ฅํ์ธ์."""
|
165 |
|
166 |
messages = [{"role": "system", "content": system_message}]
|
167 |
-
|
168 |
-
messages.append({"role": "user", "content": chat["content"]})
|
169 |
-
messages.append({"role": "assistant", "content": chat["content"]})
|
170 |
messages.append({"role": "user", "content": message})
|
171 |
|
172 |
try:
|
@@ -205,6 +200,8 @@ def create_ui():
|
|
205 |
padding: 10px 20px;
|
206 |
margin: 0;
|
207 |
transition: background-color 0.3s;
|
|
|
|
|
208 |
}
|
209 |
.tab-nav button:hover {
|
210 |
background-color: #2980b9;
|
@@ -212,19 +209,6 @@ def create_ui():
|
|
212 |
.tab-nav button.selected {
|
213 |
color: #2c3e50 !important;
|
214 |
background-color: #ecf0f1;
|
215 |
-
font-weight: bold;
|
216 |
-
}
|
217 |
-
.file-button {
|
218 |
-
background-color: #f0f0f0;
|
219 |
-
border: 1px solid #ddd;
|
220 |
-
padding: 5px 10px;
|
221 |
-
margin: 2px 0;
|
222 |
-
cursor: pointer;
|
223 |
-
text-align: left;
|
224 |
-
width: 100%;
|
225 |
-
}
|
226 |
-
.file-button:hover {
|
227 |
-
background-color: #e0e0e0;
|
228 |
}
|
229 |
input[type="text"], textarea {
|
230 |
color: #2c3e50 !important;
|
@@ -232,11 +216,10 @@ def create_ui():
|
|
232 |
}
|
233 |
"""
|
234 |
|
235 |
-
|
236 |
-
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
237 |
gr.Markdown("# HuggingFace Space Analyzer")
|
238 |
|
239 |
-
with gr.Tabs(
|
240 |
with gr.TabItem("๋ถ์"):
|
241 |
with gr.Row():
|
242 |
with gr.Column(scale=6): # ์ผ์ชฝ 60%
|
@@ -254,13 +237,10 @@ def create_ui():
|
|
254 |
|
255 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
256 |
tree_view_output = gr.Textbox(label="ํ์ผ ๊ตฌ์กฐ (Tree View)", lines=20)
|
257 |
-
|
258 |
-
with gr.Group(elem_classes="output-group scroll-lock"):
|
259 |
-
file_buttons = gr.HTML(label="ํ์ผ ๋ฆฌ์คํธ")
|
260 |
|
261 |
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
262 |
with gr.Group(elem_classes="output-group full-height"):
|
263 |
-
code_tabs = gr.Tabs(
|
264 |
with code_tabs:
|
265 |
app_py_tab = gr.TabItem("app.py")
|
266 |
with app_py_tab:
|
@@ -270,7 +250,7 @@ def create_ui():
|
|
270 |
requirements_content = gr.Textbox(label="requirements.txt", lines=30)
|
271 |
|
272 |
with gr.TabItem("AI ์ฝ๋ฉ"):
|
273 |
-
chatbot = gr.Chatbot(label="๋ํ"
|
274 |
msg = gr.Textbox(label="๋ฉ์์ง")
|
275 |
|
276 |
# ์จ๊ฒจ์ง ์ํ๋ก ํ๋ผ๋ฏธํฐ ์ค์
|
@@ -290,82 +270,27 @@ def create_ui():
|
|
290 |
gr.Examples(examples, inputs=msg)
|
291 |
|
292 |
def respond_wrapper(message, chat_history, max_tokens, temperature, top_p):
|
|
|
293 |
bot_message = respond(message, chat_history, max_tokens, temperature, top_p)
|
294 |
-
chat_history.append(
|
|
|
295 |
return "", chat_history
|
296 |
|
297 |
msg.submit(respond_wrapper, [msg, chatbot, max_tokens, temperature, top_p], [msg, chatbot])
|
298 |
|
299 |
-
|
300 |
space_id_state = gr.State()
|
301 |
tree_structure_state = gr.State()
|
302 |
|
303 |
-
def update_file_buttons(tree_structure, space_id):
|
304 |
-
if tree_structure is None:
|
305 |
-
return ""
|
306 |
-
|
307 |
-
def get_files(node):
|
308 |
-
files = []
|
309 |
-
if node["type"] == "file":
|
310 |
-
files.append(node)
|
311 |
-
elif node["type"] == "directory":
|
312 |
-
for child in node.get("children", []):
|
313 |
-
files.extend(get_files(child))
|
314 |
-
return files
|
315 |
-
|
316 |
-
files = get_files(tree_structure)
|
317 |
-
buttons_html = "<div style='display: flex; flex-direction: column;'>"
|
318 |
-
for file in files:
|
319 |
-
buttons_html += f"<button class='file-button' onclick='openFile(\"{file['path']}\", \"{space_id}\")'>{file['path']}</button>"
|
320 |
-
buttons_html += "</div>"
|
321 |
-
return buttons_html
|
322 |
-
|
323 |
-
def open_file(file_path: str, space_id: str):
|
324 |
-
content = get_file_content(space_id, file_path)
|
325 |
-
file_name = file_path.split('/')[-1]
|
326 |
-
if file_name == "requirements.txt":
|
327 |
-
return gr.Tabs.update(selected="requirements.txt"), gr.Textbox.update(value=content, label=file_name)
|
328 |
-
else:
|
329 |
-
return gr.Tabs.update(selected=file_name), gr.Code.update(value=content, language="python" if file_name.endswith('.py') else "plaintext", label=file_name)
|
330 |
-
|
331 |
analyze_button.click(
|
332 |
analyze_space,
|
333 |
inputs=[url_input],
|
334 |
outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state, summary_output, analysis_output, usage_output]
|
335 |
-
).then(
|
336 |
-
update_file_buttons,
|
337 |
-
inputs=[tree_structure_state, space_id_state],
|
338 |
-
outputs=[file_buttons]
|
339 |
).then(
|
340 |
lambda space_id: get_file_content(space_id, "requirements.txt"),
|
341 |
inputs=[space_id_state],
|
342 |
outputs=[requirements_content]
|
343 |
)
|
344 |
|
345 |
-
file_path_input = gr.Textbox(visible=False)
|
346 |
-
space_id_input = gr.Textbox(visible=False)
|
347 |
-
|
348 |
-
file_path_input.change(
|
349 |
-
open_file,
|
350 |
-
inputs=[file_path_input, space_id_input],
|
351 |
-
outputs=[code_tabs, code_tabs]
|
352 |
-
)
|
353 |
-
|
354 |
-
# JavaScript ์ฝ๋๋ฅผ HTML์ ์ง์ ์ฝ์
|
355 |
-
gr.HTML("""
|
356 |
-
<script>
|
357 |
-
function openFile(path, spaceId) {
|
358 |
-
const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
|
359 |
-
const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
|
360 |
-
if (filePathInput && spaceIdInput) {
|
361 |
-
filePathInput.value = path;
|
362 |
-
spaceIdInput.value = spaceId;
|
363 |
-
filePathInput.dispatchEvent(new Event('change'));
|
364 |
-
}
|
365 |
-
}
|
366 |
-
</script>
|
367 |
-
""")
|
368 |
-
|
369 |
return demo
|
370 |
|
371 |
except Exception as e:
|
@@ -373,7 +298,6 @@ def create_ui():
|
|
373 |
print(traceback.format_exc())
|
374 |
raise
|
375 |
|
376 |
-
|
377 |
if __name__ == "__main__":
|
378 |
try:
|
379 |
print("Starting HuggingFace Space Analyzer...")
|
@@ -386,8 +310,8 @@ if __name__ == "__main__":
|
|
386 |
|
387 |
print("Launching Gradio app...")
|
388 |
demo.launch(
|
389 |
-
server_name="0.0.0.0",
|
390 |
-
server_port=7860,
|
391 |
share=False,
|
392 |
debug=True,
|
393 |
show_api=False
|
@@ -399,4 +323,4 @@ if __name__ == "__main__":
|
|
399 |
print(traceback.format_exc())
|
400 |
raise
|
401 |
|
402 |
-
print("Script execution completed.")
|
|
|
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]
|
|
|
155 |
print(traceback.format_exc())
|
156 |
return f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", None, "", "", "", ""
|
157 |
|
|
|
158 |
def respond(message: str, chat_history: List[Dict[str, str]], max_tokens: int, temperature: float, top_p: float) -> str:
|
159 |
system_message = """๋น์ ์ ํ๊น
ํ์ด์ค์ ํนํ๋ AI ์ฝ๋ฉ ์ ๋ฌธ๊ฐ์
๋๋ค. ์ฌ์ฉ์์ ์ง๋ฌธ์ ์น์ ํ๊ณ ์์ธํ๊ฒ ๋ต๋ณํด์ฃผ์ธ์.
|
160 |
Gradio ํน์ฑ์ ์ ํํ ์ธ์ํ๊ณ Requirements.txt ๋๋ฝ์์ด ์ฝ๋ฉ๊ณผ ์ค๋ฅ๋ฅผ ํด๊ฒฐํด์ผ ํฉ๋๋ค.
|
161 |
ํญ์ ์ ํํ๊ณ ์ ์ฉํ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋๋ก ๋
ธ๋ ฅํ์ธ์."""
|
162 |
|
163 |
messages = [{"role": "system", "content": system_message}]
|
164 |
+
messages.extend(chat_history)
|
|
|
|
|
165 |
messages.append({"role": "user", "content": message})
|
166 |
|
167 |
try:
|
|
|
200 |
padding: 10px 20px;
|
201 |
margin: 0;
|
202 |
transition: background-color 0.3s;
|
203 |
+
font-size: 16px;
|
204 |
+
font-weight: bold;
|
205 |
}
|
206 |
.tab-nav button:hover {
|
207 |
background-color: #2980b9;
|
|
|
209 |
.tab-nav button.selected {
|
210 |
color: #2c3e50 !important;
|
211 |
background-color: #ecf0f1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
}
|
213 |
input[type="text"], textarea {
|
214 |
color: #2c3e50 !important;
|
|
|
216 |
}
|
217 |
"""
|
218 |
|
219 |
+
with gr.Blocks(css=css, theme=gr.themes.Default()) as demo:
|
|
|
220 |
gr.Markdown("# HuggingFace Space Analyzer")
|
221 |
|
222 |
+
with gr.Tabs() as tabs:
|
223 |
with gr.TabItem("๋ถ์"):
|
224 |
with gr.Row():
|
225 |
with gr.Column(scale=6): # ์ผ์ชฝ 60%
|
|
|
237 |
|
238 |
with gr.Group(elem_classes="output-group scroll-lock"):
|
239 |
tree_view_output = gr.Textbox(label="ํ์ผ ๊ตฌ์กฐ (Tree View)", lines=20)
|
|
|
|
|
|
|
240 |
|
241 |
with gr.Column(scale=4): # ์ค๋ฅธ์ชฝ 40%
|
242 |
with gr.Group(elem_classes="output-group full-height"):
|
243 |
+
code_tabs = gr.Tabs()
|
244 |
with code_tabs:
|
245 |
app_py_tab = gr.TabItem("app.py")
|
246 |
with app_py_tab:
|
|
|
250 |
requirements_content = gr.Textbox(label="requirements.txt", lines=30)
|
251 |
|
252 |
with gr.TabItem("AI ์ฝ๋ฉ"):
|
253 |
+
chatbot = gr.Chatbot(label="๋ํ")
|
254 |
msg = gr.Textbox(label="๋ฉ์์ง")
|
255 |
|
256 |
# ์จ๊ฒจ์ง ์ํ๋ก ํ๋ผ๋ฏธํฐ ์ค์
|
|
|
270 |
gr.Examples(examples, inputs=msg)
|
271 |
|
272 |
def respond_wrapper(message, chat_history, max_tokens, temperature, top_p):
|
273 |
+
|
274 |
bot_message = respond(message, chat_history, max_tokens, temperature, top_p)
|
275 |
+
chat_history.append({"role": "user", "content": message})
|
276 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
277 |
return "", chat_history
|
278 |
|
279 |
msg.submit(respond_wrapper, [msg, chatbot, max_tokens, temperature, top_p], [msg, chatbot])
|
280 |
|
|
|
281 |
space_id_state = gr.State()
|
282 |
tree_structure_state = gr.State()
|
283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
analyze_button.click(
|
285 |
analyze_space,
|
286 |
inputs=[url_input],
|
287 |
outputs=[app_py_content, tree_view_output, tree_structure_state, space_id_state, summary_output, analysis_output, usage_output]
|
|
|
|
|
|
|
|
|
288 |
).then(
|
289 |
lambda space_id: get_file_content(space_id, "requirements.txt"),
|
290 |
inputs=[space_id_state],
|
291 |
outputs=[requirements_content]
|
292 |
)
|
293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
return demo
|
295 |
|
296 |
except Exception as e:
|
|
|
298 |
print(traceback.format_exc())
|
299 |
raise
|
300 |
|
|
|
301 |
if __name__ == "__main__":
|
302 |
try:
|
303 |
print("Starting HuggingFace Space Analyzer...")
|
|
|
310 |
|
311 |
print("Launching Gradio app...")
|
312 |
demo.launch(
|
313 |
+
server_name="0.0.0.0",
|
314 |
+
server_port=7860,
|
315 |
share=False,
|
316 |
debug=True,
|
317 |
show_api=False
|
|
|
323 |
print(traceback.format_exc())
|
324 |
raise
|
325 |
|
326 |
+
print("Script execution completed.")
|