Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -522,63 +522,60 @@ if __name__ == "__main__":
|
|
| 522 |
server_name = os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0")
|
| 523 |
server_port = int(os.environ.get("GRADIO_SERVER_PORT", 7860))
|
| 524 |
|
| 525 |
-
#
|
| 526 |
-
with gr.Blocks(
|
| 527 |
-
gr.Markdown(""
|
| 528 |
-
|
| 529 |
-
## **SOTA RAG Coding Assistant**
|
| 530 |
|
| 531 |
-
|
|
|
|
|
|
|
| 532 |
|
| 533 |
-
|
| 534 |
-
""
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
msg = gr.Textbox(
|
| 541 |
-
placeholder="Ask anything about Python coding...",
|
| 542 |
-
label="Your Question",
|
| 543 |
-
lines=3
|
| 544 |
-
)
|
| 545 |
-
clear = gr.Button("Clear Chat")
|
| 546 |
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
["How to read a CSV file in Python?"],
|
| 551 |
-
["Why am I getting 'list index out of range' error?"],
|
| 552 |
-
["Help, my code isn't working!"],
|
| 553 |
-
],
|
| 554 |
-
inputs=msg
|
| 555 |
)
|
| 556 |
|
| 557 |
-
|
| 558 |
-
|
| 559 |
|
| 560 |
def respond(message, history):
|
| 561 |
-
|
| 562 |
-
|
| 563 |
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
respond,
|
| 566 |
[msg, chatbot],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
[msg, chatbot]
|
| 568 |
).then(
|
| 569 |
-
|
| 570 |
[msg, chatbot],
|
| 571 |
chatbot
|
| 572 |
)
|
| 573 |
|
| 574 |
clear.click(lambda: [], None, chatbot)
|
| 575 |
|
| 576 |
-
|
| 577 |
-
logger.info(f"Starting Codey Bryant 3.0 on {server_name}:{server_port}")
|
| 578 |
-
logger.info("SOTA RAG Architecture: HyDE + Query Rewriting + Multi-Query + Answer-Space Retrieval")
|
| 579 |
-
|
| 580 |
-
demo.launch(
|
| 581 |
-
server_name=server_name,
|
| 582 |
-
server_port=server_port,
|
| 583 |
-
share=False
|
| 584 |
-
)
|
|
|
|
| 522 |
server_name = os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0")
|
| 523 |
server_port = int(os.environ.get("GRADIO_SERVER_PORT", 7860))
|
| 524 |
|
| 525 |
+
# SIMPLE, WORKING UI
|
| 526 |
+
with gr.Blocks() as demo:
|
| 527 |
+
gr.Markdown("# 🤖 Codey Bryant 3.0")
|
| 528 |
+
gr.Markdown("Python Coding Assistant with SOTA RAG")
|
|
|
|
| 529 |
|
| 530 |
+
# Status and initialization
|
| 531 |
+
status = gr.Textbox("Click 'Initialize' to start", label="Status", interactive=False)
|
| 532 |
+
init_btn = gr.Button("Initialize", variant="primary")
|
| 533 |
|
| 534 |
+
# Chat interface
|
| 535 |
+
chatbot = gr.Chatbot(label="Conversation")
|
| 536 |
+
msg = gr.Textbox(placeholder="Type your Python question here...", label="Your Question")
|
| 537 |
+
submit = gr.Button("Send")
|
| 538 |
+
clear = gr.Button("Clear")
|
| 539 |
|
| 540 |
+
# Event handlers
|
| 541 |
+
def init_and_enable():
|
| 542 |
+
yield from initialize_assistant()
|
| 543 |
+
return gr.update(interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
|
| 545 |
+
init_btn.click(
|
| 546 |
+
init_and_enable,
|
| 547 |
+
outputs=[status]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
)
|
| 549 |
|
| 550 |
+
def add_message(message, history):
|
| 551 |
+
return "", history + [[message, None]]
|
| 552 |
|
| 553 |
def respond(message, history):
|
| 554 |
+
for response in chat(message, history):
|
| 555 |
+
yield response
|
| 556 |
|
| 557 |
+
# Connect the send button
|
| 558 |
+
submit.click(
|
| 559 |
+
add_message,
|
| 560 |
+
[msg, chatbot],
|
| 561 |
+
[msg, chatbot]
|
| 562 |
+
).then(
|
| 563 |
respond,
|
| 564 |
[msg, chatbot],
|
| 565 |
+
chatbot
|
| 566 |
+
)
|
| 567 |
+
|
| 568 |
+
# Also connect Enter key
|
| 569 |
+
msg.submit(
|
| 570 |
+
add_message,
|
| 571 |
+
[msg, chatbot],
|
| 572 |
[msg, chatbot]
|
| 573 |
).then(
|
| 574 |
+
respond,
|
| 575 |
[msg, chatbot],
|
| 576 |
chatbot
|
| 577 |
)
|
| 578 |
|
| 579 |
clear.click(lambda: [], None, chatbot)
|
| 580 |
|
| 581 |
+
demo.launch(server_name=server_name, server_port=server_port, share=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|