Update app.py
Browse files5 unmodified lines67891011122 unmodified lines15161718192021224 unmodified lines2728293031322 unmodified lines353637383940414 unmodified lines464748495051525 unmodified lines"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message,history: list[tuple[str, str]],2 unmodified linestemperature,top_p,):messages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})4 unmodified linesresponse = ""for message in client.chat_completion(messages,max_tokens=max_tokens,2 unmodified linestop_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response4 unmodified linesdemo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(5 unmodified lines678910112 unmodified lines14151617181920212223244 unmodified lines293031323334352 unmodified lines3839404142434 unmodified lines484950515253545 unmodified lines"""client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")def respond(message,history: list[tuple[str, str]],2 unmodified linestemperature,top_p,):# Set the default system message to the friendly Python chatbot messagesystem_message = system_message or "You are a friendly Python code writing Chatbot. Assist with Python programming tasks, debugging, and code optimization. Provide solutions for Python-related queries, help with libraries, algorithms, and best practices, and generate clean, efficient code for various applications."# Prepare the conversation history and current messagemessages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})4 unmodified linesresponse = ""# Request the response from the modelfor message in client.chat_completion(messages,max_tokens=max_tokens,2 unmodified linestop_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response4 unmodified linesdemo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Python code writing Chatbot. Assist with Python programming tasks, debugging, and code optimization. Provide solutions for Python-related queries, help with libraries, algorithms, and best practices, and generate clean, efficient code for various applications.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),gr.Slider(
app.py+6-4