Update app.py
Browse files
app.py
CHANGED
|
@@ -176,6 +176,8 @@ def respond(
|
|
| 176 |
|
| 177 |
|
| 178 |
|
|
|
|
|
|
|
| 179 |
def create_ui():
|
| 180 |
try:
|
| 181 |
css = """
|
|
@@ -199,13 +201,6 @@ def create_ui():
|
|
| 199 |
}
|
| 200 |
"""
|
| 201 |
|
| 202 |
-
js = """
|
| 203 |
-
function openFile(path, spaceId) {
|
| 204 |
-
const event = new CustomEvent('open-file', { detail: { path, spaceId } });
|
| 205 |
-
window.dispatchEvent(event);
|
| 206 |
-
}
|
| 207 |
-
"""
|
| 208 |
-
|
| 209 |
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
| 210 |
gr.Markdown("# HuggingFace Space Analyzer")
|
| 211 |
|
|
@@ -243,7 +238,7 @@ def create_ui():
|
|
| 243 |
requirements_content = gr.Textbox(label="requirements.txt", lines=30)
|
| 244 |
|
| 245 |
with gr.TabItem("AI ์ฝ๋ฉ"):
|
| 246 |
-
chatbot = gr.Chatbot()
|
| 247 |
msg = gr.Textbox(label="๋ฉ์์ง")
|
| 248 |
with gr.Row():
|
| 249 |
system_message = gr.Textbox(label="System Message", value="")
|
|
@@ -252,6 +247,7 @@ def create_ui():
|
|
| 252 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
| 253 |
|
| 254 |
examples = [
|
|
|
|
| 255 |
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
| 256 |
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
| 257 |
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
|
@@ -264,7 +260,8 @@ def create_ui():
|
|
| 264 |
|
| 265 |
def respond_wrapper(message, chat_history, system_message, max_tokens, temperature, top_p):
|
| 266 |
bot_message = respond(message, chat_history, system_message, max_tokens, temperature, top_p)
|
| 267 |
-
chat_history.append(
|
|
|
|
| 268 |
return "", chat_history
|
| 269 |
|
| 270 |
msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
|
|
@@ -326,26 +323,6 @@ def create_ui():
|
|
| 326 |
outputs=[code_tabs, code_tabs]
|
| 327 |
)
|
| 328 |
|
| 329 |
-
# JavaScript ์ฝ๋๋ฅผ HTML์ ์ง์ ์ฝ์
|
| 330 |
-
gr.HTML(f"<script>{js}</script>")
|
| 331 |
-
|
| 332 |
-
# ํ์ผ ์ด๊ธฐ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ถ๊ฐ
|
| 333 |
-
demo.load(None, None, None, _js="""
|
| 334 |
-
() => {
|
| 335 |
-
function handleOpenFile(event) {
|
| 336 |
-
const { path, spaceId } = event.detail;
|
| 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 |
-
window.addEventListener('open-file', handleOpenFile);
|
| 346 |
-
}
|
| 347 |
-
""")
|
| 348 |
-
|
| 349 |
return demo
|
| 350 |
|
| 351 |
except Exception as e:
|
|
@@ -357,7 +334,22 @@ if __name__ == "__main__":
|
|
| 357 |
try:
|
| 358 |
demo = create_ui()
|
| 359 |
demo.queue()
|
| 360 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
except Exception as e:
|
| 362 |
print(f"Error in main: {str(e)}")
|
| 363 |
-
print(traceback.format_exc())
|
|
|
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
+
|
| 180 |
+
|
| 181 |
def create_ui():
|
| 182 |
try:
|
| 183 |
css = """
|
|
|
|
| 201 |
}
|
| 202 |
"""
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
with gr.Blocks(css=css, theme="Nymbo/Nymbo_Theme") as demo:
|
| 205 |
gr.Markdown("# HuggingFace Space Analyzer")
|
| 206 |
|
|
|
|
| 238 |
requirements_content = gr.Textbox(label="requirements.txt", lines=30)
|
| 239 |
|
| 240 |
with gr.TabItem("AI ์ฝ๋ฉ"):
|
| 241 |
+
chatbot = gr.Chatbot(label="๋ํ", type="messages")
|
| 242 |
msg = gr.Textbox(label="๋ฉ์์ง")
|
| 243 |
with gr.Row():
|
| 244 |
system_message = gr.Textbox(label="System Message", value="")
|
|
|
|
| 247 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
| 248 |
|
| 249 |
examples = [
|
| 250 |
+
|
| 251 |
["์์ธํ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ๋ง์น ํ๋ฉด์ ๋ณด๋ฉด์ ์ค๋ช
ํ๋ฏ์ด 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
| 252 |
["FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
| 253 |
["์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
|
|
|
| 260 |
|
| 261 |
def respond_wrapper(message, chat_history, system_message, max_tokens, temperature, top_p):
|
| 262 |
bot_message = respond(message, chat_history, system_message, max_tokens, temperature, top_p)
|
| 263 |
+
chat_history.append({"role": "user", "content": message})
|
| 264 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
| 265 |
return "", chat_history
|
| 266 |
|
| 267 |
msg.submit(respond_wrapper, [msg, chatbot, system_message, max_tokens, temperature, top_p], [msg, chatbot])
|
|
|
|
| 323 |
outputs=[code_tabs, code_tabs]
|
| 324 |
)
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
return demo
|
| 327 |
|
| 328 |
except Exception as e:
|
|
|
|
| 334 |
try:
|
| 335 |
demo = create_ui()
|
| 336 |
demo.queue()
|
| 337 |
+
demo.launch(
|
| 338 |
+
share=False,
|
| 339 |
+
debug=True,
|
| 340 |
+
show_api=False,
|
| 341 |
+
js="""
|
| 342 |
+
function openFile(path, spaceId) {
|
| 343 |
+
const filePathInput = document.querySelector('input[data-testid="file_path_input"]');
|
| 344 |
+
const spaceIdInput = document.querySelector('input[data-testid="space_id_input"]');
|
| 345 |
+
if (filePathInput && spaceIdInput) {
|
| 346 |
+
filePathInput.value = path;
|
| 347 |
+
spaceIdInput.value = spaceId;
|
| 348 |
+
filePathInput.dispatchEvent(new Event('change'));
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
"""
|
| 352 |
+
)
|
| 353 |
except Exception as e:
|
| 354 |
print(f"Error in main: {str(e)}")
|
| 355 |
+
print(traceback.format_exc())
|