ashupanda123 commited on
Commit
d6fa718
·
verified ·
1 Parent(s): d95a7f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -14
app.py CHANGED
@@ -43,26 +43,59 @@ def respond(
43
  response += token
44
  yield response
45
 
 
46
  """
47
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
48
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  demo = gr.ChatInterface(
50
  respond,
51
- additional_inputs=[
52
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
53
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
54
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
55
- gr.Slider(
56
- minimum=0.1,
57
- maximum=1.0,
58
- value=0.95,
59
- step=0.05,
60
- label="Top-p (nucleus sampling)",
61
- ),
62
- gr.Radio(choices=["blog", "ad", "social media post"], label="Template"),
63
- ],
64
  )
65
 
 
 
 
 
66
 
67
  if __name__ == "__main__":
68
- demo.launch()
 
43
  response += token
44
  yield response
45
 
46
+
47
  """
48
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
49
  """
50
+ additional_inputs = [
51
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
52
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
53
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
+ gr.Slider(
55
+ minimum=0.1,
56
+ maximum=1.0,
57
+ value=0.95,
58
+ step=0.05,
59
+ label="Top-p (nucleus sampling)",
60
+ ),
61
+ gr.Radio(choices=["blog", "ad", "social media post"], label="Template"),
62
+ ]
63
+
64
+ # Define the copy button JavaScript
65
+ copy_js = """
66
+ function copyToClipboard(text) {
67
+ navigator.clipboard.writeText(text).then(function() {
68
+ alert('Copied to clipboard!');
69
+ }, function(err) {
70
+ alert('Failed to copy text: ', err);
71
+ });
72
+ }
73
+ """
74
+
75
+ # Add a custom button with the copy functionality
76
+ def copy_button(demo):
77
+ return gr.Button(
78
+ "Copy", variant="primary", visible=True, elem_id="copy-button"
79
+ ).click(
80
+ _js=f"""
81
+ function() {{
82
+ let response = document.querySelector(".output_textarea").value;
83
+ copyToClipboard(response);
84
+ }}
85
+ """
86
+ )
87
+
88
+ # Extend the Gradio ChatInterface
89
  demo = gr.ChatInterface(
90
  respond,
91
+ additional_inputs=additional_inputs,
92
+ additional_js=copy_js
 
 
 
 
 
 
 
 
 
 
 
93
  )
94
 
95
+ # Add the copy button
96
+ demo = demo.update(
97
+ copy_button(demo)
98
+ )
99
 
100
  if __name__ == "__main__":
101
+ demo.launch()