peterkros commited on
Commit
bc27e82
·
verified ·
1 Parent(s): 84dea3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -47,19 +47,30 @@ def generate_response(message, selected_topics):
47
  inputs = tokenizer.encode(message, return_tensors="pt")
48
  outputs = model.generate(inputs, max_length=50, do_sample=True)
49
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
50
  return response
51
 
52
 
 
 
 
 
 
 
 
 
53
 
 
 
54
 
55
- dropdown = gr.components.Dropdown(choices=topics_list, label="Select Topics", multiselect=True)
 
 
 
 
 
 
56
 
57
- iface = gr.ChatInterface(
58
- fn=generate_response,
59
- title="Child-Safe Chatbot BETA",
60
- additional_inputs=[dropdown],
61
- description="A chatbot that stays on topic and filters inappropriate content. Select relevant topics.",
62
- )
63
 
64
  # Run the app
65
  if __name__ == "__main__":
 
47
  inputs = tokenizer.encode(message, return_tensors="pt")
48
  outputs = model.generate(inputs, max_length=50, do_sample=True)
49
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
50
+ #response = f"Echo: {message}. Selected topics: {', '.join(selected_topics)}"
51
  return response
52
 
53
 
54
+ def main():
55
+ with gr.Blocks() as demo:
56
+ gr.Markdown("### Child-Safe Chatbot BETA")
57
+ with gr.Row():
58
+ message_input = gr.Textbox(label="Your Message")
59
+ topics_dropdown = gr.Dropdown(choices=topics_list, label="Select Topics", multiselect=True)
60
+ submit_btn = gr.Button("Send")
61
+ response_output = gr.Textbox(label="Bot Response")
62
 
63
+ def combined_function(message, selected_topics):
64
+ return generate_response(message, [selected_topics])
65
 
66
+ submit_btn.click(
67
+ fn=combined_function,
68
+ inputs=[message_input, topics_dropdown],
69
+ outputs=response_output
70
+ )
71
+
72
+ demo.launch()
73
 
 
 
 
 
 
 
74
 
75
  # Run the app
76
  if __name__ == "__main__":