expandme commited on
Commit
edd7b07
1 Parent(s): 0896ff0

Title refreshed ? - What wind.surf will do ?

Browse files
Files changed (1) hide show
  1. app.py +64 -66
app.py CHANGED
@@ -84,6 +84,8 @@ def respond(
84
  # Load new model if changed
85
  if current_model is None or model_name not in str(current_model.model_path):
86
  current_model = load_model(model_name)
 
 
87
 
88
  # Start with system message
89
  messages = []
@@ -121,12 +123,27 @@ def respond(
121
  def get_chat_title(model_name):
122
  return f"{model_name} < - Load different model in Additional Inputs"
123
 
124
- demo = gr.ChatInterface(
125
- respond,
126
- title=get_chat_title(list(MODELS.keys())[0]),
127
- description="GGUF is popular format, try models locclay in: [LM Studio AI for PC](https://lmstudio.ai) | PocketPal AI ([Android](https://play.google.com/store/apps/details?id=com.pocketpalai) & [iOS](https://play.google.com/store/apps/details?id=com.pocketpalai)) on Tablet or Mobile",
128
- additional_inputs=[
129
- gr.Dropdown(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  choices=list(MODELS.keys()),
131
  value=list(MODELS.keys())[0],
132
  label="Select Model",
@@ -134,68 +151,49 @@ demo = gr.ChatInterface(
134
  allow_custom_value=False,
135
  elem_id="model_selector",
136
  show_label=True
137
- ),
138
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
139
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
140
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
141
- gr.Slider(
142
- minimum=0.1,
143
- maximum=1.0,
144
- value=0.95,
145
- step=0.05,
146
- label="Top-p (nucleus sampling)",
147
- ),
148
- ],
149
- chatbot=gr.Chatbot(
150
- value=[],
151
- type="messages",
152
- label="Chat Messages"
153
- ),
154
- theme=gr.themes.Soft(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  primary_hue="blue",
156
  secondary_hue="purple",
157
- ),
158
- css="""
159
- .message-wrap {
160
- border: 1px solid #e0e0e0;
161
- border-radius: 8px;
162
- padding: 8px;
163
- margin: 8px 0;
164
- }
165
- #component-0, #component-1 {
166
- border: 4px solid #2196F3;
167
- border-radius: 12px;
168
- padding: 15px;
169
- background-color: #E3F2FD;
170
- box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
171
- margin: 10px 0;
172
- }
173
- #component-0:focus-within, #component-1:focus-within {
174
- border-color: #1976D2;
175
- box-shadow: 0 0 15px rgba(33, 150, 243, 0.5);
176
- background-color: #BBDEFB;
177
- }
178
- .input-container, .gradio-container .input-container {
179
- border: 4px solid #2196F3;
180
- border-radius: 12px;
181
- padding: 15px;
182
- background-color: #E3F2FD;
183
- box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
184
- margin: 10px 0;
185
- }
186
- .input-container textarea, .input-container input[type="text"] {
187
- background-color: #E3F2FD;
188
- border: 2px solid #2196F3;
189
- border-radius: 8px;
190
- padding: 10px;
191
- }
192
- .input-container textarea:focus, .input-container input[type="text"]:focus {
193
- background-color: #BBDEFB;
194
- border-color: #1976D2;
195
- outline: none;
196
- }
197
- """
198
- )
199
 
200
  if __name__ == "__main__":
201
  demo.launch()
 
84
  # Load new model if changed
85
  if current_model is None or model_name not in str(current_model.model_path):
86
  current_model = load_model(model_name)
87
+ # Update the interface title
88
+ gr.Info(get_chat_title(model_name))
89
 
90
  # Start with system message
91
  messages = []
 
123
  def get_chat_title(model_name):
124
  return f"{model_name} < - Load different model in Additional Inputs"
125
 
126
+ with gr.Blocks() as demo:
127
+ with gr.Row():
128
+ title = gr.HTML(value=f"<h1>{get_chat_title(list(MODELS.keys())[0])}</h1>")
129
+
130
+ with gr.Row():
131
+ chatbot = gr.Chatbot(
132
+ value=[],
133
+ type="messages",
134
+ label="Chat Messages"
135
+ )
136
+
137
+ with gr.Row():
138
+ msg = gr.Textbox(
139
+ label="Message",
140
+ placeholder="Type your message here...",
141
+ lines=1
142
+ )
143
+ submit = gr.Button("Submit")
144
+
145
+ with gr.Accordion("Additional Inputs", open=False):
146
+ model_selector = gr.Dropdown(
147
  choices=list(MODELS.keys()),
148
  value=list(MODELS.keys())[0],
149
  label="Select Model",
 
151
  allow_custom_value=False,
152
  elem_id="model_selector",
153
  show_label=True
154
+ )
155
+ system_msg = gr.Textbox(value="You are a friendly Chatbot.", label="System message")
156
+ max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
157
+ temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
158
+ top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
159
+
160
+ gr.Markdown(
161
+ "GGUF is popular model format, try HG models localy in: [LM Studio AI](https://lmstudio.ai) for PC | PocketPal AI ([Android](https://play.google.com/store/apps/details?id=com.pocketpalai) & [iOS](https://play.google.com/store/apps/details?id=com.pocketpalai)) on Tablet or Mobile"
162
+ )
163
+
164
+ def update_title(model_name):
165
+ return f"<h1>{get_chat_title(model_name)}</h1>"
166
+
167
+ model_selector.change(
168
+ fn=update_title,
169
+ inputs=[model_selector],
170
+ outputs=[title]
171
+ )
172
+
173
+ def submit_message(message, chat_history, model_name, system_message, max_tokens, temperature, top_p):
174
+ history = [] if chat_history is None else chat_history
175
+ for response in respond(message, history, model_name, system_message, max_tokens, temperature, top_p):
176
+ history = history + [[message, response]]
177
+ yield history, ""
178
+
179
+ submit_event = submit.click(
180
+ fn=submit_message,
181
+ inputs=[msg, chatbot, model_selector, system_msg, max_tokens, temperature, top_p],
182
+ outputs=[chatbot, msg],
183
+ show_progress=True,
184
+ )
185
+
186
+ msg.submit(
187
+ fn=submit_message,
188
+ inputs=[msg, chatbot, model_selector, system_msg, max_tokens, temperature, top_p],
189
+ outputs=[chatbot, msg],
190
+ show_progress=True,
191
+ )
192
+
193
+ demo.theme = gr.themes.Soft(
194
  primary_hue="blue",
195
  secondary_hue="purple",
196
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
 
198
  if __name__ == "__main__":
199
  demo.launch()