bupa1018 commited on
Commit
5e7dd2a
·
1 Parent(s): 0f75cac

Update app.py

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