script.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import gradio as gr
  2. params = {
  3. "activate": True,
  4. "bias string": " *I am so happy*",
  5. }
  6. def input_modifier(string):
  7. """
  8. This function is applied to your text inputs before
  9. they are fed into the model.
  10. """
  11. return string
  12. def output_modifier(string):
  13. """
  14. This function is applied to the model outputs.
  15. """
  16. return string
  17. def bot_prefix_modifier(string):
  18. """
  19. This function is only applied in chat mode. It modifies
  20. the prefix text for the Bot and can be used to bias its
  21. behavior.
  22. """
  23. if params['activate']:
  24. return f'{string} {params["bias string"].strip()} '
  25. else:
  26. return string
  27. def ui():
  28. # Gradio elements
  29. activate = gr.Checkbox(value=params['activate'], label='Activate character bias')
  30. string = gr.Textbox(value=params["bias string"], label='Character bias')
  31. # Event functions to update the parameters in the backend
  32. string.change(lambda x: params.update({"bias string": x}), string, None)
  33. activate.change(lambda x: params.update({"activate": x}), activate, None)