bupa1018 commited on
Commit
31d2d4e
·
1 Parent(s): 6e7d67c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -44
app.py CHANGED
@@ -74,52 +74,65 @@ initialize()
74
 
75
 
76
 
 
 
 
 
77
 
78
- import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  def main():
81
- st.set_page_config(page_title="KadiAPY - AI Coding-Assistant", layout="wide")
82
-
83
- st.title("KadiAPY - AI Coding-Assistant")
84
- st.markdown("AI assistant for KadiAPY based on RAG architecture powered by LLM")
85
-
86
- tab1, tab2 = st.tabs(["KadiAPY - AI Assistant", "Try Asking"])
87
-
88
- with tab1:
89
- st.write("### Kadi Bot")
90
-
91
- if "chat_history" not in st.session_state:
92
- st.session_state.chat_history = []
93
-
94
- # Chatbot
95
- chatbot_placeholder = st.empty()
96
- question = st.text_input("Question", placeholder="Type in your question and press Enter")
97
-
98
- if st.button("Submit"):
99
- if question:
100
- st.session_state.chat_history.append({"User": question})
101
- response = bot_kadi(question) # Replace `bot_kadi` with your response generation function
102
- st.session_state.chat_history.append({"Kadi Bot": response})
103
-
104
- if st.button("Clear"):
105
- st.session_state.chat_history = []
106
-
107
- for exchange in st.session_state.chat_history:
108
- for speaker, text in exchange.items():
109
- st.write(f"**{speaker}:** {text}")
110
-
111
- with tab2:
112
- st.write("### Try Asking...")
113
- examples = [
114
- "Write me a python script which can convert plain JSON to a Kadi4Mat-compatible extra metadata structure",
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()