Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,25 +54,28 @@ def add_text_to_chatbot(chat_history, user_input):
|
|
| 54 |
|
| 55 |
chat_history = chat_history + [(user_input, None)]
|
| 56 |
return chat_history, ""
|
| 57 |
-
|
| 58 |
|
| 59 |
def main():
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("## KadiAPY - AI Coding-Assistant")
|
| 62 |
gr.Markdown("AI assistant for KadiAPY based on RAG architecture powered by LLM")
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
with gr.Tab("KadiAPY - AI Assistant"):
|
| 65 |
with gr.Row():
|
| 66 |
with gr.Column(scale=10):
|
| 67 |
chatbot = gr.Chatbot([], elem_id="chatbot", label="Kadi Bot", bubble_full_width=False, show_copy_button=True, height=600)
|
| 68 |
user_txt = gr.Textbox(label="Question", placeholder="Type in your question and press Enter or click Submit")
|
| 69 |
-
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column(scale=1):
|
| 72 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 73 |
with gr.Column(scale=1):
|
| 74 |
clear_btn = gr.Button("Clear", variant="stop")
|
| 75 |
-
|
| 76 |
gr.Examples(
|
| 77 |
examples=[
|
| 78 |
"Write me a python script with which can convert plain JSON to a Kadi4Mat-compatible extra metadata structure",
|
|
@@ -85,11 +88,20 @@ def main():
|
|
| 85 |
cache_examples=False,
|
| 86 |
examples_per_page=3,
|
| 87 |
)
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
demo.launch()
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
if __name__ == "__main__":
|
| 95 |
main()
|
|
|
|
| 54 |
|
| 55 |
chat_history = chat_history + [(user_input, None)]
|
| 56 |
return chat_history, ""
|
| 57 |
+
|
| 58 |
|
| 59 |
def main():
|
| 60 |
with gr.Blocks() as demo:
|
| 61 |
gr.Markdown("## KadiAPY - AI Coding-Assistant")
|
| 62 |
gr.Markdown("AI assistant for KadiAPY based on RAG architecture powered by LLM")
|
| 63 |
+
|
| 64 |
+
# Create a state for session management
|
| 65 |
+
chat_history = gr.State([])
|
| 66 |
|
| 67 |
with gr.Tab("KadiAPY - AI Assistant"):
|
| 68 |
with gr.Row():
|
| 69 |
with gr.Column(scale=10):
|
| 70 |
chatbot = gr.Chatbot([], elem_id="chatbot", label="Kadi Bot", bubble_full_width=False, show_copy_button=True, height=600)
|
| 71 |
user_txt = gr.Textbox(label="Question", placeholder="Type in your question and press Enter or click Submit")
|
| 72 |
+
|
| 73 |
with gr.Row():
|
| 74 |
with gr.Column(scale=1):
|
| 75 |
submit_btn = gr.Button("Submit", variant="primary")
|
| 76 |
with gr.Column(scale=1):
|
| 77 |
clear_btn = gr.Button("Clear", variant="stop")
|
| 78 |
+
|
| 79 |
gr.Examples(
|
| 80 |
examples=[
|
| 81 |
"Write me a python script with which can convert plain JSON to a Kadi4Mat-compatible extra metadata structure",
|
|
|
|
| 88 |
cache_examples=False,
|
| 89 |
examples_per_page=3,
|
| 90 |
)
|
| 91 |
+
|
| 92 |
+
# Use the state to persist chat history between interactions
|
| 93 |
+
submit_btn.click(add_text_to_chatbot, [chat_history, user_txt], [chat_history, user_txt])\
|
| 94 |
+
.then(bot_kadi, [chat_history], [chatbot])
|
| 95 |
+
|
| 96 |
+
clear_btn.click(lambda: ([], ""), None, [chat_history, chatbot, user_txt])
|
| 97 |
|
| 98 |
demo.launch()
|
| 99 |
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
main()
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
if __name__ == "__main__":
|
| 107 |
main()
|