acecalisto3 commited on
Commit
de72f5f
·
verified ·
1 Parent(s): c87d965

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -48
app.py CHANGED
@@ -173,52 +173,52 @@ with gr.Blocks() as app:
173
  combine_button.click(combine_datasets, outputs=[combined_output, download_output])
174
 
175
  with gr.Tab("Train and Chat"):
176
- gr.Markdown("**Train a chatbot with a selected dataset and interact with it.**")
177
-
178
- chat_dataset = gr.Textbox(
179
- label="Dataset for Training",
180
- placeholder="Paste or load a dataset for training.",
181
- lines=5,
182
- )
183
- train_button = gr.Button("Train Chatbot")
184
- chatbot = gr.Chatbot(label="Chat with Trained Bot", type="messages")
185
- user_input = gr.Textbox(
186
- label="Your Message",
187
- placeholder="Type a message and press Enter...",
188
- lines=1,
189
- )
190
-
191
- # Persistent system message with dataset knowledge
192
- system_message = {"system": "You are a bot trained on the following dataset:"}
193
- bot_knowledge = {"dataset": None}
194
-
195
- # Train the chatbot by setting the dataset
196
- def train_chatbot(dataset):
197
- bot_knowledge["dataset"] = dataset
198
- return "Chatbot trained successfully!"
199
-
200
- # Chat function for handling user messages
201
- def chat_with_bot(history, user_message):
202
- if not bot_knowledge["dataset"]:
203
- return history + [{"role": "bot", "content": "No dataset loaded. Please train the bot first."}]
204
-
205
- # Append user input to history
206
- history.append({"role": "user", "content": user_message})
207
-
208
- # Generate bot response based on the dataset
209
- prompt = f"{bot_knowledge['dataset']} {user_message}"
210
- response = client.text_generation(prompt=prompt, max_new_tokens=128)["generated_text"]
211
-
212
- # Append bot response to history
213
- history.append({"role": "bot", "content": response})
214
- return history
215
-
216
- # Train button event
217
- train_button.click(train_chatbot, inputs=[chat_dataset], outputs=None)
218
-
219
- # User input submission event
220
- user_input.submit(
221
- chat_with_bot, inputs=[chatbot, user_input], outputs=chatbot
222
- )
223
-
224
  app.launch()
 
173
  combine_button.click(combine_datasets, outputs=[combined_output, download_output])
174
 
175
  with gr.Tab("Train and Chat"):
176
+ gr.Markdown("**Train a chatbot with a selected dataset and interact with it.**")
177
+
178
+ chat_dataset = gr.Textbox(
179
+ label="Dataset for Training",
180
+ placeholder="Paste or load a dataset for training.",
181
+ lines=5,
182
+ )
183
+ train_button = gr.Button("Train Chatbot")
184
+ chatbot = gr.Chatbot(label="Chat with Trained Bot", type="messages")
185
+ user_input = gr.Textbox(
186
+ label="Your Message",
187
+ placeholder="Type a message and press Enter...",
188
+ lines=1,
189
+ )
190
+
191
+ # Persistent system message with dataset knowledge
192
+ system_message = {"system": "You are a bot trained on the following dataset:"}
193
+ bot_knowledge = {"dataset": None}
194
+
195
+ # Train the chatbot by setting the dataset
196
+ def train_chatbot(dataset):
197
+ bot_knowledge["dataset"] = dataset
198
+ return "Chatbot trained successfully!"
199
+
200
+ # Chat function for handling user messages
201
+ def chat_with_bot(history, user_message):
202
+ if not bot_knowledge["dataset"]:
203
+ return history + [{"role": "bot", "content": "No dataset loaded. Please train the bot first."}]
204
+
205
+ # Append user input to history
206
+ history.append({"role": "user", "content": user_message})
207
+
208
+ # Generate bot response based on the dataset
209
+ prompt = f"{bot_knowledge['dataset']} {user_message}"
210
+ response = client.text_generation(prompt=prompt, max_new_tokens=128)["generated_text"]
211
+
212
+ # Append bot response to history
213
+ history.append({"role": "bot", "content": response})
214
+ return history
215
+
216
+ # Train button event
217
+ train_button.click(train_chatbot, inputs=[chat_dataset], outputs=None)
218
+
219
+ # User input submission event
220
+ user_input.submit(
221
+ chat_with_bot, inputs=[chatbot, user_input], outputs=chatbot
222
+ )
223
+
224
  app.launch()