Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,52 +74,65 @@ initialize()
|
|
| 74 |
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
def main():
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
"I need a method to upload a file to a record. The id of the record is 3",
|
| 116 |
-
]
|
| 117 |
-
for example in examples:
|
| 118 |
-
st.write(f"- {example}")
|
| 119 |
-
|
| 120 |
-
def bot_kadi(question):
|
| 121 |
-
# Dummy function for the AI response, replace with your logic
|
| 122 |
-
return "This is a placeholder response from Kadi Bot."
|
| 123 |
|
|
|
|
| 124 |
if __name__ == "__main__":
|
| 125 |
-
main()
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
+
def bot_kadi(history):
|
| 78 |
+
user_query = history[-1][0]
|
| 79 |
+
response = kadiAPY_bot.process_query(user_query)
|
| 80 |
+
history[-1] = (user_query, response)
|
| 81 |
|
| 82 |
+
yield history
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# Gradio utils
|
| 87 |
+
def check_input_text(text):
|
| 88 |
+
if not text:
|
| 89 |
+
gr.Warning("Please input a question.")
|
| 90 |
+
raise TypeError
|
| 91 |
+
return True
|
| 92 |
+
|
| 93 |
+
def add_text(history, text):
|
| 94 |
+
history = history + [(text, None)]
|
| 95 |
+
yield history, ""
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
import gradio as gr
|
| 99 |
|
| 100 |
def main():
|
| 101 |
+
with gr.Blocks() as demo:
|
| 102 |
+
gr.Markdown("## KadiAPY - AI Coding-Assistant")
|
| 103 |
+
gr.Markdown("AI assistant for KadiAPY based on RAG architecture powered by LLM")
|
| 104 |
+
|
| 105 |
+
with gr.Tab("KadiAPY - AI Assistant"):
|
| 106 |
+
with gr.Row():
|
| 107 |
+
with gr.Column(scale=10):
|
| 108 |
+
chatbot = gr.Chatbot([], elem_id="chatbot", label="Kadi Bot", bubble_full_width=False, show_copy_button=True, height=600)
|
| 109 |
+
user_txt = gr.Textbox(label="Question", placeholder="Type in your question and press Enter or click Submit")
|
| 110 |
+
|
| 111 |
+
with gr.Row():
|
| 112 |
+
with gr.Column(scale=1):
|
| 113 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
| 114 |
+
with gr.Column(scale=1):
|
| 115 |
+
clear_btn = gr.Button("Clear", variant="stop")
|
| 116 |
+
|
| 117 |
+
gr.Examples(
|
| 118 |
+
examples=[
|
| 119 |
+
"Write me a python script with which can convert plain JSON to a Kadi4Mat-compatible extra metadata structure",
|
| 120 |
+
"I need a method to upload a file to a record. The id of the record is 3",
|
| 121 |
+
],
|
| 122 |
+
inputs=user_txt,
|
| 123 |
+
outputs=chatbot,
|
| 124 |
+
fn=add_text,
|
| 125 |
+
label="Try asking...",
|
| 126 |
+
cache_examples=False,
|
| 127 |
+
examples_per_page=3,
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
user_txt.submit(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
|
| 131 |
+
submit_btn.click(check_input_text, user_txt, None).success(add_text, [chatbot, user_txt], [chatbot, user_txt]).then(bot_kadi, [chatbot], [chatbot])
|
| 132 |
+
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 133 |
+
|
| 134 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
+
|
| 137 |
if __name__ == "__main__":
|
| 138 |
+
main()
|