Tonic commited on
Commit
719044f
1 Parent(s): 84a2509

modify interface

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -67,9 +67,15 @@ def generate_response(message, history, system_message, max_tokens, temperature,
67
 
68
  return assistant_response
69
 
 
 
70
 
71
- def update_advanced_settings(show_advanced):
72
- return {"visible": show_advanced}
 
 
 
 
73
 
74
  with gr.Blocks() as demo:
75
  with gr.Row():
@@ -88,15 +94,13 @@ with gr.Blocks() as demo:
88
  system_prompt = gr.TextArea(label="📑Context", placeholder="add context here...", lines=5)
89
  user_input = gr.TextArea(label="🤷🏻‍♂️User Input", placeholder="Hi there my name is Tonic!", lines=2)
90
  advanced_checkbox = gr.Checkbox(label="🧪 Advanced Settings", value=False)
91
- advanced_settings = gr.Column(visible=False)
92
- with advanced_settings:
93
  max_length = gr.Slider(label="📏Max Length", minimum=12, maximum=1700, value=650, step=1)
94
  temperature = gr.Slider(label="🌡️Temperature", minimum=0.01, maximum=1.0, value=0.7, step=0.01)
95
  top_p = gr.Slider(label="⚛️Top-p (Nucleus Sampling)", minimum=0.1, maximum=1.0, value=0.9, step=0.01)
96
  use_pipeline = gr.Checkbox(label="Use Pipeline", value=False)
97
  use_tool = gr.Checkbox(label="Use Function Calling", value=False)
98
- tool_options = gr.Column(visible=False)
99
- with tool_options:
100
  tool_definition = gr.Code(
101
  label="Tool Definition (JSON)",
102
  value=customtool,
@@ -109,16 +113,6 @@ with gr.Blocks() as demo:
109
  with gr.Column(scale=2):
110
  chatbot = gr.Chatbot(label="🤖Mistral-NeMo-Minitron")
111
 
112
- def user(user_message, history):
113
- return "", history + [[user_message, None]]
114
-
115
- def bot(history, system_prompt, max_length, temperature, top_p, advanced_checkbox, use_pipeline, tool_definition):
116
- user_message = history[-1][0]
117
- do_sample = advanced_checkbox
118
- bot_message = generate_response(user_message, history, system_prompt, max_length, temperature, top_p, do_sample, use_pipeline, tool_definition)
119
- history[-1][1] = bot_message
120
- return history
121
-
122
  generate_button.click(
123
  user,
124
  [user_input, chatbot],
@@ -131,9 +125,9 @@ with gr.Blocks() as demo:
131
  )
132
 
133
  advanced_checkbox.change(
134
- fn=update_advanced_settings,
135
  inputs=[advanced_checkbox],
136
- outputs=advanced_settings
137
  )
138
 
139
  use_tool.change(
@@ -144,4 +138,4 @@ with gr.Blocks() as demo:
144
 
145
  if __name__ == "__main__":
146
  demo.queue()
147
- demo.launch()
 
67
 
68
  return assistant_response
69
 
70
+ def user(user_message, history):
71
+ return "", history + [[user_message, None]]
72
 
73
+ def bot(history, system_prompt, max_length, temperature, top_p, advanced_checkbox, use_pipeline, tool_definition):
74
+ user_message = history[-1][0]
75
+ do_sample = advanced_checkbox
76
+ bot_message = generate_response(user_message, history, system_prompt, max_length, temperature, top_p, do_sample, use_pipeline, tool_definition)
77
+ history[-1][1] = bot_message
78
+ return history
79
 
80
  with gr.Blocks() as demo:
81
  with gr.Row():
 
94
  system_prompt = gr.TextArea(label="📑Context", placeholder="add context here...", lines=5)
95
  user_input = gr.TextArea(label="🤷🏻‍♂️User Input", placeholder="Hi there my name is Tonic!", lines=2)
96
  advanced_checkbox = gr.Checkbox(label="🧪 Advanced Settings", value=False)
97
+ with gr.Column(visible=False) as advanced_settings:
 
98
  max_length = gr.Slider(label="📏Max Length", minimum=12, maximum=1700, value=650, step=1)
99
  temperature = gr.Slider(label="🌡️Temperature", minimum=0.01, maximum=1.0, value=0.7, step=0.01)
100
  top_p = gr.Slider(label="⚛️Top-p (Nucleus Sampling)", minimum=0.1, maximum=1.0, value=0.9, step=0.01)
101
  use_pipeline = gr.Checkbox(label="Use Pipeline", value=False)
102
  use_tool = gr.Checkbox(label="Use Function Calling", value=False)
103
+ with gr.Column(visible=False) as tool_options:
 
104
  tool_definition = gr.Code(
105
  label="Tool Definition (JSON)",
106
  value=customtool,
 
113
  with gr.Column(scale=2):
114
  chatbot = gr.Chatbot(label="🤖Mistral-NeMo-Minitron")
115
 
 
 
 
 
 
 
 
 
 
 
116
  generate_button.click(
117
  user,
118
  [user_input, chatbot],
 
125
  )
126
 
127
  advanced_checkbox.change(
128
+ fn=lambda x: gr.update(visible=x),
129
  inputs=[advanced_checkbox],
130
+ outputs=[advanced_settings]
131
  )
132
 
133
  use_tool.change(
 
138
 
139
  if __name__ == "__main__":
140
  demo.queue()
141
+ demo.launch()